[llvm] [InstCombine] Fix invalid IR when folding frexp(frexp(x)) with mismatched exponent types (PR #202419)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 12:50:21 PDT 2026


================
@@ -4256,16 +4245,17 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     break;
   case Intrinsic::frexp: {
     Value *X;
-    // The first result is idempotent with the added complication of the struct
-    // return, and the second result is zero because the value is already
-    // normalized.
-    if (match(II->getArgOperand(0), m_ExtractValue<0>(m_Value(X)))) {
-      if (match(X, m_Intrinsic<Intrinsic::frexp>(m_Value()))) {
-        X = Builder.CreateInsertValue(
-            X, Constant::getNullValue(II->getType()->getStructElementType(1)),
-            1);
-        return replaceInstUsesWith(*II, X);
-      }
+    // frexp(frexp(x).fract) -> { frexp(x).fract, 0 }: the fraction operand is
+    // already normalized, so the first result is idempotent and the second is
+    // zero.
+    if (match(II->getArgOperand(0), m_ExtractValue<0>(m_Value(X))) &&
+        match(X, m_Intrinsic<Intrinsic::frexp>(m_Value()))) {
----------------
nikic wrote:

Could drop the intermediate X variable, as you no longer need the value. Up to you.

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


More information about the llvm-commits mailing list