]> granicus.if.org Git - llvm/commitdiff
Merging r277114:
authorHans Wennborg <hans@hanshq.net>
Mon, 1 Aug 2016 20:30:12 +0000 (20:30 +0000)
committerHans Wennborg <hans@hanshq.net>
Mon, 1 Aug 2016 20:30:12 +0000 (20:30 +0000)
------------------------------------------------------------------------
r277114 | majnemer | 2016-07-28 22:39:21 -0700 (Thu, 28 Jul 2016) | 6 lines

[EarlyCSE] Correctly handle simplified, but live, instructions

Some instructions may have their uses replaced with a symbolic constant.
However, the instruction may still have side effects which percludes it
from being removed from the function.  EarlyCSE treated such an
instruction as if it were removed, resulting in PR28763.
------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@277382 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/EarlyCSE.cpp
test/Transforms/EarlyCSE/basic.ll

index 9d0ef42e0396d7a42405ec7f8f14a6c720bfef23..0b16e2703dc48505d83495cc4b9ba5526bd8f12a 100644 (file)
@@ -582,6 +582,7 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
     // its simpler value.
     if (Value *V = SimplifyInstruction(Inst, DL, &TLI, &DT, &AC)) {
       DEBUG(dbgs() << "EarlyCSE Simplify: " << *Inst << "  to: " << *V << '\n');
+      bool Killed = false;
       if (!Inst->use_empty()) {
         Inst->replaceAllUsesWith(V);
         Changed = true;
@@ -589,11 +590,12 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
       if (isInstructionTriviallyDead(Inst, &TLI)) {
         Inst->eraseFromParent();
         Changed = true;
+        Killed = true;
       }
-      if (Changed) {
+      if (Changed)
         ++NumSimplify;
+      if (Killed)
         continue;
-      }
     }
 
     // If this is a simple instruction that we can value number, process it.
index fa1a7059db9556d4d7a85a4408e25b6851cd4ca0..3c427d899f681d7e773d78cefcf0f471e81c5986 100644 (file)
@@ -276,3 +276,17 @@ define void @dse_neg2(i32 *%P) {
   ret void
 }
 
+@c = external global i32, align 4
+declare i32 @reads_c(i32 returned)
+define void @pr28763() {
+entry:
+; CHECK-LABEL: @pr28763(
+; CHECK: store i32 0, i32* @c, align 4
+; CHECK: call i32 @reads_c(i32 0)
+; CHECK: store i32 2, i32* @c, align 4
+  %load = load i32, i32* @c, align 4
+  store i32 0, i32* @c, align 4
+  %call = call i32 @reads_c(i32 0)
+  store i32 2, i32* @c, align 4
+  ret void
+}