This patch enables SimplifyDemandedUseBits to handle PhiNode so that some redundant instructions across the PhiNode can be eliminated.
Details
Diff Detail
Event Timeline
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | ||
---|---|---|
680 | Use "KnownZero &= PhiOperandKnown.Zero" it will save an allocation if the width is more than 64-bits. |
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | ||
---|---|---|
473 | see the comments below. | |
476 | I actually did not understand why DemandedMaskIn is reset here. So I moved it down (after processed the operand 0). To me, since we are doing the do the shift right, ShiftAmt of the lowbits is not needed (whatever value it might be). If the lowbits in DemandMaskin are indeed needed, I would have to set the Known.zero and check Known.zero in AND instruction. |
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | ||
---|---|---|
476 | If we dont' preserve the bits in the input to the shift, then the exact flag could become incorrect. I'm not sure why we would prefer to preserve the bits rather than clear the exact flag. |
Interesting. NewGVN can already figure this out if it's important.
How often does stuff like this occur?
test/Transforms/InstCombine/simplify-demanded-bits-across-phi.ll | ||
---|---|---|
36 | Remove the ss :) |
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | ||
---|---|---|
476 | You are right! Thanks for the explanation. If the operand marked as exact, it's unsafe the remove the AND operation. Changed the test case as suggested by dberlin. |
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | ||
---|---|---|
679 | This call is going to be expensive in the case where the PHI node refers to itself (either directly or indirectly). It's not an infinite loop due to the depth limit, but we might want to limit the recursion some other way. |
This seems unrelated or at least unexplained.