[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 09:25:23 PDT 2016


Carrot created this revision.
Carrot added a reviewer: majnemer.
Carrot added a subscriber: llvm-commits.

This patch fixes https://llvm.org/bugs/show_bug.cgi?id=27703.

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.

http://reviews.llvm.org/D20173

Files:
  lib/Transforms/InstCombine/InstCombineCasts.cpp

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.56927.patch
Type: text/x-patch
Size: 673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160511/a6fc7085/attachment.bin>


More information about the llvm-commits mailing list