<div dir="ltr"><div class="gmail_default" style="font-size:large">ping</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 11, 2016 at 4:12 PM, Guozhi Wei <span dir="ltr"><<a href="mailto:carrot@google.com" target="_blank">carrot@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Carrot updated this revision to Diff 56976.<br>
Carrot added a comment.<br>
<br>
The original patch considers only one load instruction. There may be multiple load instructions, each loaded value is used as address of later load instruction, just as Caroline's testcase, it still causes problem. This updated patch solves the problem. Detecting the exact pattern is too complex. For simplicity the code gives up if the load address comes from another load instruction.<br>
<br>
Please review it again.<br>
<span class=""><br>
<br>
<a href="http://reviews.llvm.org/D20173" rel="noreferrer" target="_blank">http://reviews.llvm.org/D20173</a><br>
<br>
Files:<br>
  lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
  test/Transforms/InstCombine/pr27703.ll<br>
<br>
Index: test/Transforms/InstCombine/pr27703.ll<br>
===================================================================<br>
--- test/Transforms/InstCombine/pr27703.ll<br>
+++ test/Transforms/InstCombine/pr27703.ll<br>
</span>@@ -0,0 +1,20 @@<br>
<span class="">+; RUN: opt < %s -instcombine -S | FileCheck %s<br>
+<br>
+define void @mem() {<br>
+bb:<br>
+  br label %bb6<br>
+<br>
+bb6:<br>
</span>+  %.0 = phi i8** [ undef, %bb ], [ %t2, %bb6 ]<br>
<span class="">+  %tmp = load i8*, i8** %.0, align 8<br>
+  %bc = bitcast i8* %tmp to i8**<br>
</span>+  %t1 = load i8*, i8** %bc, align 8<br>
+  %t2 = bitcast i8* %t1 to i8**<br>
<span class="">+  br label %bb6<br>
+<br>
+bb206:<br>
+  ret void<br>
+; CHECK: phi<br>
+; CHECK: bitcast<br>
+; CHECK: load<br>
+}<br>
</span><span class="">Index: lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
===================================================================<br>
--- lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
+++ lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
</span>@@ -1820,6 +1820,13 @@<br>
<span class=""><br>
       auto *LI = dyn_cast<LoadInst>(IncValue);<br>
       if (LI) {<br>
</span>+        // 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>
<div class="HOEnZb"><div class="h5">+          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>
<br>
</div></div></blockquote></div><br></div></div>