[llvm] r315429 - [GVN] Don't replace constants with constants.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 21:21:51 PDT 2017


Author: davide
Date: Tue Oct 10 21:21:51 2017
New Revision: 315429

URL: http://llvm.org/viewvc/llvm-project?rev=315429&view=rev
Log:
[GVN] Don't replace constants with constants.

This fixes PR34908. Patch by Alex Crichton!

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

Added:
    llvm/trunk/test/Transforms/GVN/pr34908.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/GVN.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=315429&r1=315428&r2=315429&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Tue Oct 10 21:21:51 2017
@@ -1362,6 +1362,11 @@ bool GVN::processAssumeIntrinsic(Intrins
     }
     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());

Added: llvm/trunk/test/Transforms/GVN/pr34908.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/pr34908.ll?rev=315429&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GVN/pr34908.ll (added)
+++ llvm/trunk/test/Transforms/GVN/pr34908.ll Tue Oct 10 21:21:51 2017
@@ -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)




More information about the llvm-commits mailing list