[llvm] [VPlan] Mark unary ops as not having side-effects (NFC). (PR #190554)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 5 15:30:38 PDT 2026
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/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.
>From 8cbd014c1449bfc072244fc0ff21988b00b41728 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Sun, 5 Apr 2026 15:13:08 +0100
Subject: [PATCH] [VPlan] Mark unary ops as not having side-effects (NFC).
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 8323d0d8562a4..b496278ebd6ec 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 ec9c904a08b2c..017aa6dab705e 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, {});
More information about the llvm-commits
mailing list