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, {});