[llvm] [InstSimplify] Expose simplifyIntrinsic (NFC) (PR #202577)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 9 08:23:28 PDT 2026


================
@@ -7393,38 +7380,46 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
 
     return nullptr;
   }
-  case Intrinsic::experimental_constrained_fadd: {
-    auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
-    return simplifyFAddInst(Args[0], Args[1], FPI->getFastMathFlags(), Q,
-                            *FPI->getExceptionBehavior(),
-                            *FPI->getRoundingMode());
-  }
-  case Intrinsic::experimental_constrained_fsub: {
-    auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
-    return simplifyFSubInst(Args[0], Args[1], FPI->getFastMathFlags(), Q,
-                            *FPI->getExceptionBehavior(),
-                            *FPI->getRoundingMode());
-  }
-  case Intrinsic::experimental_constrained_fmul: {
-    auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
-    return simplifyFMulInst(Args[0], Args[1], FPI->getFastMathFlags(), Q,
-                            *FPI->getExceptionBehavior(),
-                            *FPI->getRoundingMode());
-  }
-  case Intrinsic::experimental_constrained_fdiv: {
-    auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
-    return simplifyFDivInst(Args[0], Args[1], FPI->getFastMathFlags(), Q,
-                            *FPI->getExceptionBehavior(),
-                            *FPI->getRoundingMode());
-  }
-  case Intrinsic::experimental_constrained_frem: {
-    auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
-    return simplifyFRemInst(Args[0], Args[1], FPI->getFastMathFlags(), Q,
-                            *FPI->getExceptionBehavior(),
-                            *FPI->getRoundingMode());
-  }
+  case Intrinsic::experimental_constrained_fadd:
+    return simplifyFAddInst(Args[0], Args[1], FMF, Q, ExBehavior, Rounding);
+  case Intrinsic::experimental_constrained_fsub:
+    return simplifyFSubInst(Args[0], Args[1], FMF, Q, ExBehavior, Rounding);
+  case Intrinsic::experimental_constrained_fmul:
+    return simplifyFMulInst(Args[0], Args[1], FMF, Q, ExBehavior, Rounding);
+  case Intrinsic::experimental_constrained_fdiv:
+    return simplifyFDivInst(Args[0], Args[1], FMF, Q, ExBehavior, Rounding);
+  case Intrinsic::experimental_constrained_frem:
+    return simplifyFRemInst(Args[0], Args[1], FMF, Q, ExBehavior, Rounding);
   case Intrinsic::experimental_constrained_ldexp:
     return simplifyLdexp(Args[0], Args[1], Q, true);
+  case Intrinsic::experimental_vp_reverse: {
+    Value *Vec = Args[0];
+    Value *EVL = Args[2];
+
+    Value *X;
+    // vp.reverse(vp.reverse(X)) == X (mask doesn't matter)
+    if (match(Vec, m_Intrinsic<Intrinsic::experimental_vp_reverse>(
+                       m_Value(X), m_Value(), m_Specific(EVL))))
+      return X;
+
+    // vp.reverse(splat(X)) -> splat(X) (regardless of mask and EVL)
+    if (isSplatValue(Vec))
+      return Vec;
+    return nullptr;
+  }
+  default:
+    return nullptr;
+  }
+}
+
+static Value *simplifyIntrinsic(CallBase *Call, ArrayRef<Value *> Args,
+                                const SimplifyQuery &Q) {
+  // Operand bundles should not be in Args.
+  assert(Call->arg_size() == Args.size());
+  Intrinsic::ID IID = Call->getCalledFunction()->getIntrinsicID();
+  Type *ReturnType = Call->getCalledFunction()->getReturnType();
+
+  switch (IID) {
   case Intrinsic::experimental_gc_relocate: {
     GCRelocateInst &GCR = *cast<GCRelocateInst>(Call);
----------------
nikic wrote:

Is this just kept here because it uses GCRelocateInst?

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


More information about the llvm-commits mailing list