circt icon indicating copy to clipboard operation
circt copied to clipboard

[CombFolds] Relax block optimization barrier by pulling constants

Open fzi-hielscher opened this issue 1 year ago • 1 comments

This is an attempt at reducing the conservativeness of the cross-block optimization barrier introduced in #6235. See also #6523.

If canonicalization of an operation is prevented due to an operand defined outside of its block, check if all of these operands are ConstantLike. If so, create a copy of them inside of the operation's block, in the hope that this enables optimization in the next iteration. I do not love this approach, as it causes movements/duplications even if doesn't have any benefit. But I feel this is the lesser evil compared to leaving chunks of dead code float around because a trivial fold like a & false -> false is being prevented.

Is this relaxation acceptable for your use case, @mortbopet @teqdruid ? Am I missing a more elegant solution?

fzi-hielscher avatar Jun 04 '24 15:06 fzi-hielscher

Thank you for your comments. After giving some more thought to this I actually don't like this approach at all anymore. 😅 Firstly, there is the problem @mortbopet mentioned over in #6523: If the constant does not fold after moving, the hoisting and pulling get into a tug of war, which repeatedly causes pointless iterations. Secondly, a & false -> false still won't fold if a is non-local. So, it kind of misses the point. Let's try harder...

fzi-hielscher avatar Jun 05 '24 12:06 fzi-hielscher

Fortunately made obsolete by #8611 .

fzi-hielscher avatar Jun 27 '25 14:06 fzi-hielscher