[llvm] [SLP] NFC. Use InstructionsState::valid if users just want to know whether VL has same opcode. (PR #120217)
Han-Kuan Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 26 10:03:57 PST 2024
================
@@ -8144,9 +8147,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
}
// Don't handle scalable vectors
- if (S.getOpcode() == Instruction::ExtractElement &&
- isa<ScalableVectorType>(
- cast<ExtractElementInst>(S.getMainOp())->getVectorOperandType())) {
+ if (auto *EE = dyn_cast_if_present<ExtractElementInst>(S.getMainOp());
----------------
HanKuanChen wrote:
1. The origin code check MainOp opcode (`S.getOpcode() == Instruction::ExtractElement`) and use `cast` later. I think use `dyn_cast_if_present` is better.
```
if (S.getOpcode() == Instruction::ExtractElement &&
isa<ScalableVectorType>(
cast<ExtractElementInst>(S.getMainOp())->getVectorOperandType())) {
```
2. There is a case which uses `isa_and_present`. Follow the same idea, I use `dyn_cast_if_present` here.
```
bool AreAllSameInsts = AreAllSameBlock || AreScatterAllGEPSameBlock;
if (!AreAllSameInsts || (!S && allConstant(VL)) || isSplat(VL) ||
(isa_and_present<InsertElementInst, ExtractValueInst, ExtractElementInst>(
S.getMainOp()) &&
!all_of(VL, isVectorLikeInstWithConstOps)) ||
NotProfitableForVectorization(VL)) {
```
https://github.com/llvm/llvm-project/pull/120217
More information about the llvm-commits
mailing list