[llvm] [InstSimplify] Simplify extractvalue (umul_with_overflow(x, 1)). (PR #157307)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 7 03:03:44 PDT 2025


================
@@ -5242,6 +5242,19 @@ static Value *simplifyExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
     }
   }
 
+  // Simplify umul_with_overflow where one operand is 1.
+  Value *V;
+  if (Idxs.size() == 1 &&
+      (match(Agg,
+             m_Intrinsic<Intrinsic::umul_with_overflow>(m_Value(V), m_One())) ||
+       match(Agg, m_Intrinsic<Intrinsic::umul_with_overflow>(m_One(),
+                                                             m_Value(V))))) {
+    if (Idxs[0] == 0)
+      return V;
+    assert(Idxs[0] == 1 && "invalid index");
+    return getFalse(IntegerType::get(V->getContext(), 1));
----------------
fhahn wrote:

Added a test, thanks! The type isn't easily available here I think, so I updated the code to use `CmpInst::makeCmpResultType(V->getType())`

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


More information about the llvm-commits mailing list