<div dir="ltr">Hi Carrot,<div><br></div><div>I've reverted this and the previous patch here:</div><div><br></div><div><div>Committing to <a href="https://llvm.org/svn/llvm-project/llvm/trunk">https://llvm.org/svn/llvm-project/llvm/trunk</a> ...</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>D<span class="Apple-tab-span" style="white-space:pre">   </span>test/Transforms/InstCombine/pr25342.ll</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>D<span class="Apple-tab-span" style="white-space:pre">   </span>test/Transforms/InstCombine/pr27703.ll</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>M<span class="Apple-tab-span" style="white-space:pre">   </span>lib/Transforms/InstCombine/InstCombineCasts.cpp</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>M<span class="Apple-tab-span" style="white-space:pre">   </span>lib/Transforms/InstCombine/InstCombineInternal.h</div><div>Committed r274094</div></div><div><br></div><div>as was discussed in <a href="http://reviews.llvm.org/D20847">http://reviews.llvm.org/D20847</a>.</div><div><br></div><div>Thanks1</div><div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 19, 2016 at 2:13 PM Guozhi Wei via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: carrot<br>
Date: Thu May 19 16:07:01 2016<br>
New Revision: 270135<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=270135&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=270135&view=rev</a><br>
Log:<br>
[InstCombine] Avoid combining the bitcast of a var that is used as both address and result of load instructions<br>
<br>
This patch fixes <a href="https://llvm.org/bugs/show_bug.cgi?id=27703" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=27703</a>.<br>
<br>
If there is a sequence of one or more load instructions, each loaded value is used as address of later load instruction, bitcast is necessary to change the value type, don't optimize it.<br>
<br>
<br>
Added:<br>
    llvm/trunk/test/Transforms/InstCombine/pr27703.ll<br>
Modified:<br>
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=270135&r1=270134&r2=270135&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=270135&r1=270134&r2=270135&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Thu May 19 16:07:01 2016<br>
@@ -1820,6 +1820,13 @@ Instruction *InstCombiner::optimizeBitCa<br>
<br>
       auto *LI = dyn_cast<LoadInst>(IncValue);<br>
       if (LI) {<br>
+        // If there is a sequence of one or more load instructions, each loaded<br>
+        // value is used as address of later load instruction, bitcast is<br>
+        // necessary to change the value type, don't optimize it. For<br>
+        // simplicity we give up if the load address comes from another load.<br>
+        Value *Addr = LI->getOperand(0);<br>
+        if (Addr == &CI || isa<LoadInst>(Addr))<br>
+          return nullptr;<br>
         if (LI->hasOneUse() && LI->isSimple())<br>
           continue;<br>
         // If a LoadInst has more than one use, changing the type of loaded<br>
<br>
Added: llvm/trunk/test/Transforms/InstCombine/pr27703.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pr27703.ll?rev=270135&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pr27703.ll?rev=270135&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/InstCombine/pr27703.ll (added)<br>
+++ llvm/trunk/test/Transforms/InstCombine/pr27703.ll Thu May 19 16:07:01 2016<br>
@@ -0,0 +1,20 @@<br>
+; RUN: opt < %s -instcombine -S | FileCheck %s<br>
+<br>
+define void @mem() {<br>
+bb:<br>
+  br label %bb6<br>
+<br>
+bb6:<br>
+  %.0 = phi i8** [ undef, %bb ], [ %t2, %bb6 ]<br>
+  %tmp = load i8*, i8** %.0, align 8<br>
+  %bc = bitcast i8* %tmp to i8**<br>
+  %t1 = load i8*, i8** %bc, align 8<br>
+  %t2 = bitcast i8* %t1 to i8**<br>
+  br label %bb6<br>
+<br>
+bb206:<br>
+  ret void<br>
+; CHECK: phi<br>
+; CHECK: bitcast<br>
+; CHECK: load<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>