[llvm] [ConstraintElim] Remove const op restriction from tightenBoundUsingNe. (PR #213440)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 1 05:41:03 PDT 2026
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/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
>From 1f7190605cc3a13cd992eaad3053b599cd5e4ed0 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Thu, 30 Jul 2026 16:36:43 +0100
Subject: [PATCH] [ConstraintElim] Remove const op restriction from
tightenBoundUsingNe.
---
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 efe1920486df6..8b7018f6c8433 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<StackEntry> &DFSInStack) {
- if (!isa<ConstantInt>(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 baf44151a4b61..af2b5b2b9deec 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)
More information about the llvm-commits
mailing list