[llvm] 23390e7 - [InstCombine] Handle logical and/or in assume optimization
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 12 13:36:52 PST 2021
Author: Nikita Popov
Date: 2021-01-12T22:36:40+01:00
New Revision: 23390e7a131a67fd70e26692fc83f62860dd1095
URL: https://github.com/llvm/llvm-project/commit/23390e7a131a67fd70e26692fc83f62860dd1095
DIFF: https://github.com/llvm/llvm-project/commit/23390e7a131a67fd70e26692fc83f62860dd1095.diff
LOG: [InstCombine] Handle logical and/or in assume optimization
assume(a && b) can be converted to assume(a); assume(b) even if
the condition is logical. Same for assume(!(a || b)).
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/assume.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 8f2e694f3c5b..7d63b30d35f8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1478,14 +1478,14 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
FunctionType *AssumeIntrinsicTy = II->getFunctionType();
Value *AssumeIntrinsic = II->getCalledOperand();
Value *A, *B;
- if (match(IIOperand, m_And(m_Value(A), m_Value(B)))) {
+ if (match(IIOperand, m_LogicalAnd(m_Value(A), m_Value(B)))) {
Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, A, OpBundles,
II->getName());
Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, B, II->getName());
return eraseInstFromFunction(*II);
}
// assume(!(a || b)) -> assume(!a); assume(!b);
- if (match(IIOperand, m_Not(m_Or(m_Value(A), m_Value(B))))) {
+ if (match(IIOperand, m_Not(m_LogicalOr(m_Value(A), m_Value(B))))) {
Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic,
Builder.CreateNot(A), OpBundles, II->getName());
Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic,
diff --git a/llvm/test/Transforms/InstCombine/assume.ll b/llvm/test/Transforms/InstCombine/assume.ll
index f46ffbec2ce6..b107af16bdc1 100644
--- a/llvm/test/Transforms/InstCombine/assume.ll
+++ b/llvm/test/Transforms/InstCombine/assume.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -instcombine -S -instcombine-infinite-loop-threshold=2 | FileCheck %s
+; RUN: opt < %s -instcombine -S -instcombine-infinite-loop-threshold=2 -instcombine-unsafe-select-transform=0 | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@@ -627,7 +627,7 @@ define i32 @unreachable_assume_logical(i32 %x, i32 %y) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP0:%.*]] = icmp sgt i32 [[X:%.*]], 1
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[Y:%.*]], 1
-; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP0]], [[CMP1]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[CMP0]], i1 true, i1 [[CMP1]]
; CHECK-NEXT: tail call void @llvm.assume(i1 [[OR]])
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[X]], 1
; CHECK-NEXT: br i1 [[CMP2]], label [[IF:%.*]], label [[EXIT:%.*]]
@@ -704,7 +704,7 @@ define i32 @unreachable_assumes_and_store_logical(i32 %x, i32 %y, i32* %p) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP0:%.*]] = icmp sgt i32 [[X:%.*]], 1
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[Y:%.*]], 1
-; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP0]], [[CMP1]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[CMP0]], i1 true, i1 [[CMP1]]
; CHECK-NEXT: tail call void @llvm.assume(i1 [[OR]])
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[X]], 1
; CHECK-NEXT: br i1 [[CMP2]], label [[IF:%.*]], label [[EXIT:%.*]]
More information about the llvm-commits
mailing list