[llvm] [InstCombine][RISCV] Convert VPIntrinsics with splat operands to splats (PR #65706)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 11 11:07:53 PDT 2023
================
@@ -729,6 +730,96 @@ bool VectorCombine::foldBitcastShuf(Instruction &I) {
return true;
}
+/// VP Intrinsics whose vector operands are both splat values may be simplified
+/// into the scalar version of the operation and the result is splatted. This
+/// can lead to scalarization down the line.
+bool VectorCombine::scalarizeVPIntrinsic(VPIntrinsic &VPI) {
+ Value *Op0 = VPI.getArgOperand(0);
+ Value *Op1 = VPI.getArgOperand(1);
+
+ if (!getSplatValue(Op0) || !getSplatValue(Op1))
+ return false;
+
+ // For the binary VP intrinsics supported here, the result on disabled lanes
+ // is a poison value. For now, only do this simplification if all lanes
+ // are active.
+ // TODO: Relax the condition that all lanes are active by using insertelement
+ // on inactive lanes.
+ auto IsAllTrueMask = [](Value *MaskVal) {
+ if (Value *SplattedVal = getSplatValue(MaskVal))
+ if (auto *ConstValue = dyn_cast<Constant>(SplattedVal))
+ return ConstValue->isAllOnesValue();
+ return false;
+ };
+ if (!IsAllTrueMask(VPI.getArgOperand(2)))
+ return false;
----------------
lukel97 wrote:
Nit: I think `Constant::isAllOnesValue()` already checks if it's a constant splat vector, can we simplify this to something like
```suggestion
if (!isa<Constant>(Mask) || !cast<Constant>(Mask)->isAllOnesValue())
return false;
```
https://github.com/llvm/llvm-project/pull/65706
More information about the llvm-commits
mailing list