<div dir="ltr"><div><div><div>Hi Sanjay,<br><br></div>unfortunately that patch does not help in my case. Here's the IR that fails to get fully optimized:<br><br>    target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>    target triple = "x86_64-unknown-linux-gnu"<br><br>    define fastcc zeroext i1 @testfunc(i8** noalias nocapture readonly dereferenceable(8)) unnamed_addr {<br>    entry-block:<br>      %1 = load i8*, i8** %0, align 8<br>      %2 = icmp ne i8* %1, null<br>      %.mux = zext i1 %2 to i8<br>      br i1 %2, label %bb10, label %bb15<br><br>    bb10:                                             ; preds = %entry-block<br>      %3 = load i8, i8* %1, align 1<br>      %4 = icmp eq i8 %3, 42<br>      %.1 = zext i1 %4 to i8<br>      br label %bb15<br><br>    bb15:                                             ; preds = %entry-block, %bb10<br>      %_0.1 = phi i8 [ %.mux, %entry-block ], [ %.1, %bb10 ]<br>      %5 = icmp ne i8 %_0.1, 0<br>      ret i1 %5<br>    }<br><br></div>The zext instructions should be folded into the phi, and then the new zext gets removed along with the icmp instruction at the end.<br></div><div><br></div><div>Björn<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-01-30 20:20 GMT+01:00 Sanjay Patel <span dir="ltr"><<a href="mailto:spatel@rotateright.com" target="_blank">spatel@rotateright.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>I'm looking at a similar problem in:<br><a href="https://reviews.llvm.org/D28625" target="_blank">https://reviews.llvm.org/D2862<wbr>5</a><br><br></div>Does that patch make any difference on the cases that you are looking at?<br><br></div>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?<br><br>I'm not sure yet, but there's a chance that change might induce problems (infinite loops) with this:<br><a href="https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L374" target="_blank">https://github.com/llvm-mirror<wbr>/llvm/blob/master/lib/Transfor<wbr>ms/InstCombine/InstCombineSimp<wbr>lifyDemanded.cpp#L374</a><br><div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sun, Jan 29, 2017 at 3:09 PM, Björn Steinbrink via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div><div><div>Hi,<br><br></div>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.<br><br>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.<br><br></div>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?<br><br></div>Thanks<span class="m_-3943333840047646804HOEnZb"><font color="#888888"><br></font></span></div><span class="m_-3943333840047646804HOEnZb"><font color="#888888">Björn<br></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>