[llvm] [VPlan] Introduce VPlanConstantFolder (PR #125365)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 24 05:04:00 PDT 2025


================
@@ -931,9 +932,21 @@ static void recursivelyDeleteDeadRecipes(VPValue *V) {
 }
 
 /// Try to simplify recipe \p R.
-static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
+static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo,
+                           const DataLayout &DL) {
   using namespace llvm::VPlanPatternMatch;
 
+  // Constant folding.
+  VPConstantFolder Folder(DL, TypeInfo);
+  TypeSwitch<VPRecipeBase *, void>(&R)
+      .Case<VPInstruction, VPWidenRecipe, VPWidenCastRecipe, VPReplicateRecipe>(
+          [&](auto *I) {
+            VPlan *Plan = R.getParent()->getPlan();
+            ArrayRef<VPValue *> Ops(I->op_begin(), I->op_end());
+            if (Value *V = Folder.tryToConstantFold(R, I->getOpcode(), Ops))
+              R.getVPSingleValue()->replaceAllUsesWith(Plan->getOrAddLiveIn(V));
----------------
lukel97 wrote:

We should probably return from simplifyRecipe here if R is now dead?

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


More information about the llvm-commits mailing list