[llvm] [InstCombine] Infer exact for lshr by cttz (PR #136696)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 22 07:55:34 PDT 2025


================
@@ -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()) {  
----------------
nikic wrote:

Why do we need the second parameter to be one? Can you please also add an alive2 proof for the transform to the PR description?

https://github.com/llvm/llvm-project/pull/136696


More information about the llvm-commits mailing list