[llvm] [VectorCombine] Use isSafeToSpeculativelyExecute to guard VP scalarization (PR #69494)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 18 12:03:58 PDT 2023
================
@@ -825,23 +825,28 @@ bool VectorCombine::scalarizeVPIntrinsic(Instruction &I) {
ElementCount EC = cast<VectorType>(Op0->getType())->getElementCount();
Value *EVL = VPI.getArgOperand(3);
const DataLayout &DL = VPI.getModule()->getDataLayout();
- bool MustHaveNonZeroVL =
- IntrID == Intrinsic::vp_sdiv || IntrID == Intrinsic::vp_udiv ||
- IntrID == Intrinsic::vp_srem || IntrID == Intrinsic::vp_urem;
-
- if (!MustHaveNonZeroVL || isKnownNonZero(EVL, DL, 0, &AC, &VPI, &DT)) {
- Value *ScalarOp0 = getSplatValue(Op0);
- Value *ScalarOp1 = getSplatValue(Op1);
- Value *ScalarVal =
- ScalarIntrID
- ? Builder.CreateIntrinsic(VecTy->getScalarType(), *ScalarIntrID,
- {ScalarOp0, ScalarOp1})
- : Builder.CreateBinOp((Instruction::BinaryOps)(*FunctionalOpcode),
- ScalarOp0, ScalarOp1);
- replaceValue(VPI, *Builder.CreateVectorSplat(EC, ScalarVal));
- return true;
- }
- return false;
+
+ bool SafeToSpeculate;
+ if (ScalarIntrID)
+ SafeToSpeculate = Intrinsic::getAttributes(I.getContext(), *ScalarIntrID)
+ .hasFnAttr(Attribute::AttrKind::Speculatable);
+ else
+ SafeToSpeculate = isSafeToSpeculativelyExecuteWithOpcode(
+ *FunctionalOpcode, &VPI, nullptr, &AC, &DT);
+ if (!SafeToSpeculate && !isKnownNonZero(EVL, DL, 0, &AC, &VPI, &DT))
----------------
lukel97 wrote:
No worries, thanks for taking a look
https://github.com/llvm/llvm-project/pull/69494
More information about the llvm-commits
mailing list