[llvm] [vectorcombine] Pull sext/zext through reduce.or/and/xor (PR #99548)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 13:31:08 PDT 2024


================
@@ -2133,35 +2138,39 @@ bool VectorCombine::foldTruncFromReductions(Instruction &I) {
   unsigned ReductionOpc = getArithmeticReductionInstruction(IID);
   Value *ReductionSrc = I.getOperand(0);
 
-  Value *TruncSrc;
-  if (!match(ReductionSrc, m_OneUse(m_Trunc(m_Value(TruncSrc)))))
+  Value *Src;
+  if (!match(ReductionSrc, m_OneUse(m_Trunc(m_Value(Src)))) &&
+      (TruncOnly || !match(ReductionSrc, m_OneUse(m_ZExtOrSExt(m_Value(Src))))))
     return false;
 
-  auto *TruncSrcTy = cast<VectorType>(TruncSrc->getType());
+  // Note: Only trunc has a constexpr, neither sext or zext do.
----------------
nikic wrote:

m_Trunc() doesn't match trunc constant expressions (anymore), so it's safe to unconditionally cast.

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


More information about the llvm-commits mailing list