Please add a testcase.<br><br>On Wednesday, May 11, 2016, Guozhi Wei <<a href="mailto:carrot@google.com">carrot@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Carrot created this revision.<br>
Carrot added a reviewer: majnemer.<br>
Carrot added a subscriber: llvm-commits.<br>
<br>
This patch fixes <a href="https://llvm.org/bugs/show_bug.cgi?id=27703" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=27703</a>.<br>
<br>
In the testcase, the result of a load instruction is used as the address of the same instruction, so a bitcast is necessary to change the value type to address type, we should avoid to optimize out the bitcast.<br>
<br>
<a href="http://reviews.llvm.org/D20173" target="_blank">http://reviews.llvm.org/D20173</a><br>
<br>
Files:<br>
  lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
<br>
Index: lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
===================================================================<br>
--- lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
+++ lib/Transforms/InstCombine/InstCombineCasts.cpp<br>
@@ -1820,6 +1820,10 @@<br>
<br>
       auto *LI = dyn_cast<LoadInst>(IncValue);<br>
       if (LI) {<br>
+        // If the loaded value is used as the load address in the same<br>
+        // instruction, bitcast is necessary to change the value type.<br>
+        if (LI->getOperand(0) == &CI)<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>
<br>
</blockquote>