OSDN Git Service

[GVN] Don't replace constants with constants.
authorDavide Italiano <davide@freebsd.org>
Wed, 11 Oct 2017 04:21:51 +0000 (04:21 +0000)
committerDavide Italiano <davide@freebsd.org>
Wed, 11 Oct 2017 04:21:51 +0000 (04:21 +0000)
This fixes PR34908. Patch by Alex Crichton!

Differential Revision:  https://reviews.llvm.org/D38765

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315429 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVN.cpp
test/Transforms/GVN/pr34908.ll [new file with mode: 0644]

index 4e24d75..c3cc237 100644 (file)
@@ -1362,6 +1362,11 @@ bool GVN::processAssumeIntrinsic(IntrinsicInst *IntrinsicI) {
     }
     markInstructionForDeletion(IntrinsicI);
     return false;
+  } else if (isa<Constant>(V)) {
+    // If it's not false, and constant, it must evaluate to true. This means our
+    // assume is assume(true), and thus, pointless, and we don't want to do
+    // anything more here.
+    return false;
   }
 
   Constant *True = ConstantInt::getTrue(V->getContext());
diff --git a/test/Transforms/GVN/pr34908.ll b/test/Transforms/GVN/pr34908.ll
new file mode 100644 (file)
index 0000000..c2b58ad
--- /dev/null
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -gvn -S | FileCheck %s
+
+define i1 @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:    call void @llvm.assume(i1 undef)
+; CHECK-NEXT:    ret i1 undef
+;
+  call void @llvm.assume(i1 undef)
+  ret i1 undef
+}
+
+declare void @llvm.assume(i1)