[PATCH] D20173: [InstCombine] Avoid combining the bitcast of a var that is used as both address and result of the same load instruction

Guozhi Wei via llvm-commits llvm-commits at lists.llvm.org
Wed May 11 10:06:30 PDT 2016


Carrot updated this revision to Diff 56933.
Carrot added a comment.

Testcase added.


http://reviews.llvm.org/D20173

Files:
  lib/Transforms/InstCombine/InstCombineCasts.cpp
  test/Transforms/InstCombine/pr27703.ll

Index: test/Transforms/InstCombine/pr27703.ll
===================================================================
--- test/Transforms/InstCombine/pr27703.ll
+++ test/Transforms/InstCombine/pr27703.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instcombine -S
+
+define void @mem() {
+bb:
+  br label %bb6
+
+bb6:
+  %.0 = phi i8** [ undef, %bb ], [ %bc, %bb6 ]
+  %tmp = load i8*, i8** %.0, align 8
+  %bc = bitcast i8* %tmp to i8**
+  br label %bb6
+
+bb206:
+  ret void
+}
Index: lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1820,6 +1820,10 @@
 
       auto *LI = dyn_cast<LoadInst>(IncValue);
       if (LI) {
+        // If the loaded value is used as the load address in the same
+        // instruction, bitcast is necessary to change the value type.
+        if (LI->getOperand(0) == &CI)
+          return nullptr;
         if (LI->hasOneUse() && LI->isSimple())
           continue;
         // If a LoadInst has more than one use, changing the type of loaded


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20173.56933.patch
Type: text/x-patch
Size: 1139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160511/7e43c81e/attachment.bin>


More information about the llvm-commits mailing list