[llvm-dev] Folding zext from i1 into PHI nodes with only zwo incoming values.

Björn Steinbrink via llvm-dev llvm-dev at lists.llvm.org
Sun Jan 29 14:09:09 PST 2017


Hi,

AFAICT there are two places where zext instructions may get folded into PHI
nodes. One is FoldPHIArgZextsIntoPHI and the other is the more generic
FoldPHIArgOpIntoPHI. Now, the former only handles PHIs with more than 2
incoming values, while the latter only handles casts where the source type
is legal.

This means that for an PHI node with two incoming i8 values, both resulting
from `zext i1 * to i8` instructions, both of these functions will refuse to
actually fold the zext into the PHI, while the same operation would be
performed if there were three or more arms. We noticed this because we saw
a optimization regression when a function got specialized and the PHI node
only had two incoming values left.

Since I'm not fully aware of any implications this might have, I wonder
what is the right way to fix this? Looking at FoldPHIArgZextsIntoPHI, it
seems that making the check for `ShouldChangeType` in FoldPHIArgOpIntoPHI
conditional on the cast instruction not being a zext instruction. Does that
sound right, or am I missing something here?

Thanks
Björn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170129/0251168f/attachment.html>


More information about the llvm-dev mailing list