[llvm] [InstCombine] Infer exact for lshr by cttz (PR #136696)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 27 02:09:33 PDT 2025
https://github.com/houngkoungting updated https://github.com/llvm/llvm-project/pull/136696
>From 19aa8f27dac6a3c7483bbd081143b5efc410da2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=83=E5=9C=8B=E5=BA=AD?=
<37643576+houngkoungting at users.noreply.github.com>
Date: Tue, 22 Apr 2025 21:32:43 +0800
Subject: [PATCH 1/2] Update InstCombineShifts.cpp
---
.../lib/Transforms/InstCombine/InstCombineShifts.cpp | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 90cd279e8a457..c39b7dae434e0 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -994,6 +994,18 @@ static bool setShiftFlags(BinaryOperator &I, const SimplifyQuery &Q) {
I.setIsExact();
return true;
}
+ //Fix #131444
+ if (auto *Cttz = dyn_cast<IntrinsicInst>(I.getOperand(1))) {
+ if (Cttz->getIntrinsicID() == Intrinsic::cttz &&
+ Cttz->getOperand(0) == I.getOperand(0)) {
+ if (auto *Const = dyn_cast<ConstantInt>(Cttz->getOperand(1))) {
+ if (Const->isOne()) {
+ I.setIsExact();
+ return true;
+ }
+ }
+ }
+ }
}
// Compute what we know about shift count.
>From 213dc72d165a3904b09b7a117e08fce25b518fe8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=83=E5=9C=8B=E5=BA=AD?= <we3223 at gmail.com>
Date: Sun, 27 Apr 2025 17:09:25 +0800
Subject: [PATCH 2/2] Update InstCombineShifts.cpp
---
.../Transforms/InstCombine/InstCombineShifts.cpp | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index c39b7dae434e0..280a414c77dae 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -994,17 +994,11 @@ static bool setShiftFlags(BinaryOperator &I, const SimplifyQuery &Q) {
I.setIsExact();
return true;
}
- //Fix #131444
- if (auto *Cttz = dyn_cast<IntrinsicInst>(I.getOperand(1))) {
- if (Cttz->getIntrinsicID() == Intrinsic::cttz &&
- Cttz->getOperand(0) == I.getOperand(0)) {
- if (auto *Const = dyn_cast<ConstantInt>(Cttz->getOperand(1))) {
- if (Const->isOne()) {
- I.setIsExact();
- return true;
- }
- }
- }
+ // Infer 'exact' flag if shift amount is cttz(x, 1) on the same operand.
+ if (match(I.getOperand(1), m_Intrinsic<Intrinsic::cttz>(
+ m_Specific(I.getOperand(0)), m_One()))) {
+ I.setIsExact();
+ return true;
}
}
More information about the llvm-commits
mailing list