[llvm] cbf7b52 - [VPlan] Properly update reduction live-out after placing select.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 2 07:22:34 PST 2023


Author: Florian Hahn
Date: 2023-12-02T15:22:09Z
New Revision: cbf7b52a65890ea72cb6319bfdf98d92dd9ddc81

URL: https://github.com/llvm/llvm-project/commit/cbf7b52a65890ea72cb6319bfdf98d92dd9ddc81
DIFF: https://github.com/llvm/llvm-project/commit/cbf7b52a65890ea72cb6319bfdf98d92dd9ddc81.diff

LOG: [VPlan] Properly update reduction live-out after placing select.

After inserting a select for the final value, update the VPlan def-use
chains. At the moment, the incorrect live-out doesn't cause a
mis-compile, as computing the final reduction value is not yet modeled
in VPlan.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 09a6e01226ab6..496cd0dc96396 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -9271,6 +9271,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
               ? new VPInstruction(Instruction::Select, {Cond, Red, PhiR}, FMFs)
               : new VPInstruction(Instruction::Select, {Cond, Red, PhiR});
       Result->insertBefore(&*Builder.getInsertPoint());
+      Red->replaceUsesWithIf(
+          Result->getVPSingleValue(),
+          [](VPUser &U, unsigned) { return isa<VPLiveOut>(&U); });
       if (PreferPredicatedReductionSelect ||
           TTI.preferPredicatedReductionSelect(
               PhiR->getRecurrenceDescriptor().getOpcode(), PhiTy,

diff  --git a/llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll b/llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
index f0d669ad225f8..3198f19a8f9a9 100644
--- a/llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
+++ b/llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
@@ -214,7 +214,7 @@ define i32 @sink_replicate_region_3_reduction(i32 %x, i8 %y, ptr %ptr) optsize {
 ; CHECK-NEXT: middle.block:
 ; CHECK-NEXT: No successors
 ; CHECK-EMPTY:
-; CHECK-NEXT: Live-out i32 %res = ir<%and.red.next>
+; CHECK-NEXT: Live-out i32 %res = vp<[[SEL]]>
 ; CHECK-NEXT: }
 ;
 entry:


        


More information about the llvm-commits mailing list