[llvm] [VPlan] Don't rely on region check in isUniformAfterVectorization. (PR #137883)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 30 13:30:28 PDT 2025
================
@@ -39,18 +39,37 @@ const SCEV *getSCEVExprForVPValue(VPValue *V, ScalarEvolution &SE);
/// Returns true if \p VPV is uniform after vectorization.
inline bool isUniformAfterVectorization(const VPValue *VPV) {
+ auto IsKnownUniformOpcode = [](auto *R) -> bool {
+ return Instruction::isBinaryOp(R->getOpcode()) ||
+ Instruction::isCast(R->getOpcode()) ||
+ R->getOpcode() == Instruction::GetElementPtr ||
+ R->getOpcode() == Instruction::ICmp ||
+ R->getOpcode() == Instruction::FCmp;
+ };
+
// A value defined outside the vector region must be uniform after
// vectorization inside a vector region.
- if (VPV->isDefinedOutsideLoopRegions())
+ if (VPV->isLiveIn())
return true;
- if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV))
- return Rep->isUniform();
+ if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) {
+ const VPRegionBlock *ParentR = Rep->getParent()->getParent();
+ return Rep->isUniform() ||
+ (IsKnownUniformOpcode(Rep) &&
+ (!ParentR || !ParentR->isReplicator()) &&
+ all_of(Rep->operands(), isUniformAfterVectorization));
+ }
+
if (isa<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe>(VPV))
return all_of(VPV->getDefiningRecipe()->operands(),
isUniformAfterVectorization);
+ if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) {
+ return IsKnownUniformOpcode(WidenR) &&
+ all_of(WidenR->operands(), isUniformAfterVectorization);
----------------
fhahn wrote:
I am planning to look into a general system to have some relatively lightweight traits, also for flags.
As for encoding uniformity information, probably the best way is to convert it to uniform recipes; will share a transform for that soon
https://github.com/llvm/llvm-project/pull/137883
More information about the llvm-commits
mailing list