[llvm] [InstCombine] Infer exact for lshr by cttz (PR #136696)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 22 06:37:25 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: 黃國庭 (houngkoungting)
<details>
<summary>Changes</summary>
Fix #<!-- -->131444
This patch adds a pattern . It match to infer the 'exact' flag on an 'lshr' instruction when the shift amount is computed via a 'cttz' intrinsic on the same operand.
---
Full diff: https://github.com/llvm/llvm-project/pull/136696.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp (+12)
``````````diff
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/136696
More information about the llvm-commits
mailing list