[llvm] 91ce8e1 - [GVN] Use that assume(!X) implies X==false (PR47496)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 12:34:58 PDT 2020
Author: Nikita Popov
Date: 2020-09-17T21:34:44+02:00
New Revision: 91ce8e121b7f24ef68fad0ab07f6ab7e1ee06855
URL: https://github.com/llvm/llvm-project/commit/91ce8e121b7f24ef68fad0ab07f6ab7e1ee06855
DIFF: https://github.com/llvm/llvm-project/commit/91ce8e121b7f24ef68fad0ab07f6ab7e1ee06855.diff
LOG: [GVN] Use that assume(!X) implies X==false (PR47496)
We already use that assume(X) implies X==true, do the same for
assume(!X) implying X==false. This fixes PR47496.
Added:
Modified:
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/assume.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 2523cb178ddb..f8e8e2c773f9 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -1612,6 +1612,11 @@ bool GVN::processAssumeIntrinsic(IntrinsicInst *IntrinsicI) {
// br i1 %cmp, label %bb1, label %bb2 ; will change %cmp to true
ReplaceOperandsWithMap[V] = True;
+ // Similarly, after assume(!NotV) we know that NotV == false.
+ Value *NotV;
+ if (match(V, m_Not(m_Value(NotV))))
+ ReplaceOperandsWithMap[NotV] = ConstantInt::getFalse(V->getContext());
+
// If we find an equality fact, canonicalize all dominated uses in this block
// to one of the two values. We heuristically choice the "oldest" of the
// two where age is determined by value number. (Note that propagateEquality
diff --git a/llvm/test/Transforms/GVN/assume.ll b/llvm/test/Transforms/GVN/assume.ll
index 206fbbb8c390..ef2865791715 100644
--- a/llvm/test/Transforms/GVN/assume.ll
+++ b/llvm/test/Transforms/GVN/assume.ll
@@ -19,7 +19,7 @@ define void @assume_not_arg(i1 %x) {
; CHECK-LABEL: @assume_not_arg(
; CHECK-NEXT: [[XOR:%.*]] = xor i1 [[X:%.*]], true
; CHECK-NEXT: call void @llvm.assume(i1 [[XOR]])
-; CHECK-NEXT: call void @use(i1 [[X]])
+; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: ret void
;
%xor = xor i1 %x, true
@@ -33,7 +33,7 @@ define void @pr47496(i8 %x) {
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: [[XOR:%.*]] = xor i1 [[CMP]], true
; CHECK-NEXT: call void @llvm.assume(i1 [[XOR]])
-; CHECK-NEXT: call void @use(i1 [[CMP]])
+; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: ret void
;
%cmp = icmp slt i8 %x, 0
More information about the llvm-commits
mailing list