[llvm] [Instcombine] Fold away shift in or reduction chain. (PR #137875)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 00:49:52 PDT 2025


================
@@ -5046,6 +5046,29 @@ static Instruction *foldICmpOrXX(ICmpInst &I, const SimplifyQuery &Q,
   return nullptr;
 }
 
+static Value *foldShiftAwayFromOrChain(Instruction &I,
+                                       InstCombiner::BuilderTy &Builder) {
+  if (I.getOpcode() != Instruction::Or)
+    return nullptr;
+  Value *A, *B;
+  if (match(&I, m_c_Or(m_CombineOr(m_NSWShl(m_Value(A), m_Value()),
+                                   m_NUWShl(m_Value(A), m_Value())),
+                       m_Value(B))))
+    return Builder.CreateOr(A, B);
+
+  Value *Op0 = I.getOperand(0);
+  if (isa<Instruction>(Op0))
----------------
dtcxzyw wrote:

We can use `dyn_cast` instead of `isa + cast`.


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


More information about the llvm-commits mailing list