[llvm] [InstCombine] Fold extended add/sub of the same type (PR #185259)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 8 04:37:16 PDT 2026


================
@@ -1081,6 +1081,28 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
 
   Value *A, *B;
   Constant *C;
+  ConstantInt *CInt;
+
+  if (match(Src, m_UMin(m_Add(m_ZExt(m_Value(A)), m_ZExt(m_Value(B))),
+                        m_ConstantInt(CInt)))) {
----------------
andjo403 wrote:

`m_ConstantInt` will not match a vector so better to use `m_APInt` or in this case maybe even better with `m_SpecificInt(APInt::getMaxValue(DestWidth))` and then the `APInt::isSameValue` check can be dropped

also possible to combine the two ifs to one and drop the {} as there only is one instruction in the body.

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


More information about the llvm-commits mailing list