[llvm-dev] Folding zext from i1 into PHI nodes with only zwo incoming values.
Daniel Berlin via llvm-dev
llvm-dev at lists.llvm.org
Mon Jan 30 12:13:05 PST 2017
The foldPhiOpArgIntoPhi looks like a few special cases of the general
transform (that is applicable as a rewrite rule):
phi(F(1,2,...), F(A,B,...),...) == F(phi(1,A,...), phi(1,B,...), ...)
This follows directly from phis being conditional selects.
a = b + c
b = d + e
result = phi(a, b)
is equivalent to
tmp1 = phi(b, d)
tmp2 = phi(c, e)
result = tmp1 + tmp2
this is true for any number of operators and operations.
The downside is fixpointing this rule (and even probably the one being used
in foldPhiOpArgIntoPhi) is that it may require exponential applications of
On Mon, Jan 30, 2017 at 11:20 AM, Sanjay Patel via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> I'm looking at a similar problem in:
> Does that patch make any difference on the cases that you are looking at?
> Instead of avoiding ShouldChangeType with zext as a special-case opcode,
> it might be better to treat i1 as a special-case type. There's no way to
> avoid i1 in IR, so we might as well allow transforming to that type?
> I'm not sure yet, but there's a chance that change might induce problems
> (infinite loops) with this:
> On Sun, Jan 29, 2017 at 3:09 PM, Björn Steinbrink via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>> 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?
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev