From f7cdebb47863ae413f24ebd727a1dd075688d011 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 6 Apr 2026 09:05:38 +0100 Subject: [PATCH] [VPlan] Mark unary ops as not having side-effects (NFC). (#190554) Mark unary ops (only FNeg current) to neither read nor write memory, similar to binary and cast ops. Should currently be NFC end-to-end. --- llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 3 ++- llvm/unittests/Transforms/Vectorize/VPlanTest.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 8323d0d8562a..b496278ebd6e 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -1329,7 +1329,8 @@ void VPInstruction::execute(VPTransformState &State) { } bool VPInstruction::opcodeMayReadOrWriteFromMemory() const { - if (Instruction::isBinaryOp(getOpcode()) || Instruction::isCast(getOpcode())) + if (Instruction::isBinaryOp(getOpcode()) || + Instruction::isUnaryOp(getOpcode()) || Instruction::isCast(getOpcode())) return false; switch (getOpcode()) { case Instruction::GetElementPtr: diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp index ec9c904a08b2..017aa6dab705 100644 --- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp @@ -1441,6 +1441,16 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) { EXPECT_FALSE(Recipe.mayWriteToMemory()); EXPECT_FALSE(Recipe.mayReadOrWriteMemory()); } + { + VPValue *Op1 = Plan.getConstantInt(Int32, 1); + VPInstruction VPInst(Instruction::FNeg, {Op1}, + VPIRFlags::getDefaultFlags(Instruction::FNeg)); + VPRecipeBase &Recipe = VPInst; + EXPECT_FALSE(Recipe.mayHaveSideEffects()); + EXPECT_FALSE(Recipe.mayReadFromMemory()); + EXPECT_FALSE(Recipe.mayWriteToMemory()); + EXPECT_FALSE(Recipe.mayReadOrWriteMemory()); + } { VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1)); VPPredInstPHIRecipe Recipe(Op1, {});