[VPlan] Mark load VPWidenMemoryInstruction as not having side-effects.
authorFlorian Hahn <flo@fhahn.com>
Tue, 7 Feb 2023 22:02:50 +0000 (22:02 +0000)
committerFlorian Hahn <flo@fhahn.com>
Tue, 7 Feb 2023 22:02:50 +0000 (22:02 +0000)
Also add an assert using the underlying instruction to catch any
potential violations.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

index 3498111..ff0b1df 100644 (file)
@@ -127,6 +127,13 @@ bool VPRecipeBase::mayHaveSideEffects() const {
            "underlying instruction has side-effects");
     return false;
   }
+  case VPWidenMemoryInstructionSC:
+    assert(cast<VPWidenMemoryInstructionRecipe>(this)
+                   ->getIngredient()
+                   .mayHaveSideEffects() == mayWriteToMemory() &&
+           "mayHaveSideffects result for ingredient differs from this "
+           "implementation");
+    return mayWriteToMemory();
   case VPReplicateSC: {
     auto *R = cast<VPReplicateRecipe>(this);
     return R->getUnderlyingInstr()->mayHaveSideEffects();
index a879799..ff7ee53 100644 (file)
@@ -1100,7 +1100,7 @@ TEST(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
     VPValue Addr;
     VPValue Mask;
     VPWidenMemoryInstructionRecipe Recipe(*Load, &Addr, &Mask, true, false);
-    EXPECT_TRUE(Recipe.mayHaveSideEffects());
+    EXPECT_FALSE(Recipe.mayHaveSideEffects());
     EXPECT_TRUE(Recipe.mayReadFromMemory());
     EXPECT_FALSE(Recipe.mayWriteToMemory());
     EXPECT_TRUE(Recipe.mayReadOrWriteMemory());