From 78909083d74f2509ffbb8481680eb27ed5e8679a Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 1 Aug 2026 17:01:45 +0200 Subject: [PATCH] [ConstraintElim] Remove const op restriction from tightenBoundUsingNe. (#213440) Remove the constant operand restriction for the bounds tightening logic added in https://github.com/llvm/llvm-project/pull/213049. The condition is not needed for correctness, and there are a number of cases in practice where results can be improved: https://github.com/dtcxzyw/llvm-opt-benchmark-nightly/pull/839 Compile-time impact in the noise https://llvm-compile-time-tracker.com/compare.php?from=60f965b1f62c0c77bcdb2997ea9bb6603aa0d002&to=1f7190605cc3a13cd992eaad3053b599cd5e4ed0&stat=instructions:u PR: https://github.com/llvm/llvm-project/pull/213440 --- llvm/lib/Transforms/Scalar/ConstraintElimination.cpp | 2 +- llvm/test/Transforms/ConstraintElimination/ne-tightening.ll | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index efe1920486df..8b7018f6c843 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -1793,7 +1793,7 @@ void ConstraintInfo::addFact(CmpInst::Predicate Pred, Value *A, Value *B, void ConstraintInfo::tightenBoundUsingNe( Value *A, Value *B, unsigned NumIn, unsigned NumOut, SmallVectorImpl &DFSInStack) { - if (!isa(B) || !A->getType()->isIntegerTy()) + if (!A->getType()->isIntegerTy()) return; for (bool IsSigned : {false, true}) { diff --git a/llvm/test/Transforms/ConstraintElimination/ne-tightening.ll b/llvm/test/Transforms/ConstraintElimination/ne-tightening.ll index baf44151a4b6..af2b5b2b9dee 100644 --- a/llvm/test/Transforms/ConstraintElimination/ne-tightening.ll +++ b/llvm/test/Transforms/ConstraintElimination/ne-tightening.ll @@ -242,8 +242,7 @@ define i1 @neg_ne_non_constant(i64 %n, i64 %m) { ; CHECK-NEXT: call void @llvm.assume(i1 [[A]]) ; CHECK-NEXT: [[B:%.*]] = icmp ne i64 [[N]], [[M]] ; CHECK-NEXT: call void @llvm.assume(i1 [[B]]) -; CHECK-NEXT: [[C:%.*]] = icmp sgt i64 [[N]], [[M]] -; CHECK-NEXT: ret i1 [[C]] +; CHECK-NEXT: ret i1 true ; %a = icmp sge i64 %n, %m call void @llvm.assume(i1 %a)