[llvm] [VPlan] Replace disjoint or with add instead of dropping disjoint. (PR #83821)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 27 12:13:11 PDT 2024
================
@@ -1216,6 +1216,23 @@ void VPlanTransforms::dropPoisonGeneratingRecipes(
// load/store. If the underlying instruction has poison-generating flags,
// drop them directly.
if (auto *RecWithFlags = dyn_cast<VPRecipeWithIRFlags>(CurRec)) {
+ VPValue *A, *B;
+ using namespace llvm::VPlanPatternMatch;
+ // Dropping disjoint from an OR may yield incorrect results, as some
+ // analysis may have converted it to an Add implicitly (e.g. SCEV used
+ // for dependence analysis). Instead, replace it with an equivalent Add.
+ // This is possible as all users of the disjoint OR only access lanes
+ // where the operands are disjoint or poison otherwise.
+ if (match(RecWithFlags, m_Or(m_VPValue(A), m_VPValue(B))) &&
+ RecWithFlags->isDisjoint()) {
+ VPBuilder Builder(RecWithFlags);
+ VPInstruction *New = Builder.createOverflowingOp(
+ Instruction::Add, {A, B}, {false, false},
+ RecWithFlags->getDebugLoc());
+ RecWithFlags->replaceAllUsesWith(New);
+ RecWithFlags->eraseFromParent();
+ CurRec = New;
+ }
RecWithFlags->dropPoisonGeneratingFlags();
----------------
fhahn wrote:
Missed that this was reverted, recommitted with a fix.
https://github.com/llvm/llvm-project/pull/83821
More information about the llvm-commits
mailing list