[llvm] [InstCombine] Propagate exact flags in shift-combines (PR #88340)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 10 23:03:40 PDT 2024


================
@@ -1395,11 +1395,17 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
     }
 
     // (X >>u C1) >>u C --> X >>u (C1 + C)
-    if (match(Op0, m_LShr(m_Value(X), m_APInt(C1)))) {
+    Instruction *Inst;
+    if (match(Op0, m_Instruction(Inst)) &&
+        match(Inst, m_LShr(m_Value(X), m_APInt(C1)))) {
       // Oversized shifts are simplified to zero in InstSimplify.
       unsigned AmtSum = ShAmtC + C1->getZExtValue();
-      if (AmtSum < BitWidth)
-        return BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, AmtSum));
+      if (AmtSum < BitWidth) {
+        auto *NewLShr =
+            BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, AmtSum));
+        NewLShr->setIsExact(I.isExact() && Inst->isExact());
+        return NewLShr;
+      }
----------------
goldsteinn wrote:

Which proof is assosiated w/ this one?
Just a tip, you can put multiple proofs in the same alive2 by matching postfixes. For example: https://alive2.llvm.org/ce/z/P6HRvw

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


More information about the llvm-commits mailing list