[llvm] 4d8e849 - [ConstraintElim] Add facts for llvm.abs >= 0 (#79070)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 6 15:16:45 PST 2024
Author: Alexander Shaposhnikov
Date: 2024-02-06T15:16:41-08:00
New Revision: 4d8e849dfbf3ca1301f208a7286b31215d2a94db
URL: https://github.com/llvm/llvm-project/commit/4d8e849dfbf3ca1301f208a7286b31215d2a94db
DIFF: https://github.com/llvm/llvm-project/commit/4d8e849dfbf3ca1301f208a7286b31215d2a94db.diff
LOG: [ConstraintElim] Add facts for llvm.abs >= 0 (#79070)
Add facts for llvm.abs >= 0.
https://alive2.llvm.org/ce/z/GXnMHu
Added:
Modified:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
llvm/test/Transforms/ConstraintElimination/abs.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 97cf5ebe3ca06..db05c63f388fb 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -1755,7 +1755,10 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
if (!CB.isConditionFact()) {
Value *X;
if (match(CB.Inst, m_Intrinsic<Intrinsic::abs>(m_Value(X)))) {
- // TODO: Add CB.Inst >= 0 fact.
+ // If is_int_min_poison is true then we may assume llvm.abs >= 0.
+ if (cast<ConstantInt>(CB.Inst->getOperand(1))->isOne())
+ AddFact(CmpInst::ICMP_SGE, CB.Inst,
+ ConstantInt::get(CB.Inst->getType(), 0));
AddFact(CmpInst::ICMP_SGE, CB.Inst, X);
continue;
}
diff --git a/llvm/test/Transforms/ConstraintElimination/abs.ll b/llvm/test/Transforms/ConstraintElimination/abs.ll
index a7b20997fa4cd..9fc68b0e72663 100644
--- a/llvm/test/Transforms/ConstraintElimination/abs.ll
+++ b/llvm/test/Transforms/ConstraintElimination/abs.ll
@@ -142,8 +142,7 @@ define i1 @abs_is_nonnegative_int_min_is_poison(i32 %arg) {
; CHECK-LABEL: define i1 @abs_is_nonnegative_int_min_is_poison(
; CHECK-SAME: i32 [[ARG:%.*]]) {
; CHECK-NEXT: [[ABS:%.*]] = tail call i32 @llvm.abs.i32(i32 [[ARG]], i1 true)
-; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[ABS]], 0
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 true
;
%abs = tail call i32 @llvm.abs.i32(i32 %arg, i1 true)
%cmp = icmp sge i32 %abs, 0
@@ -153,8 +152,7 @@ define i1 @abs_is_nonnegative_int_min_is_poison(i32 %arg) {
define i1 @abs_is_nonnegative_constant_arg() {
; CHECK-LABEL: define i1 @abs_is_nonnegative_constant_arg() {
; CHECK-NEXT: [[ABS:%.*]] = tail call i32 @llvm.abs.i32(i32 -3, i1 true)
-; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[ABS]], 0
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 true
;
%abs = tail call i32 @llvm.abs.i32(i32 -3, i1 true)
%cmp = icmp sge i32 %abs, 0
More information about the llvm-commits
mailing list