[llvm] Reapply "[LoopUnroll] Support parallel reductions for minmax" (PR #201010)

Madhur Amilkanthwar via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 06:26:47 PDT 2026


================
@@ -1534,9 +1535,18 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
         Builder.setFastMathFlags(Reductions.begin()->second.getFastMathFlags());
         RecurKind RK = Reductions.begin()->second.getRecurrenceKind();
         for (Instruction *RdxPart : drop_begin(PartialReductions)) {
-          RdxResult = Builder.CreateBinOp(
-              (Instruction::BinaryOps)RecurrenceDescriptor::getOpcode(RK),
-              RdxPart, RdxResult, "bin.rdx");
+          if (RecurrenceDescriptor::isMinMaxRecurrenceKind(RK)) {
+            RdxResult = createMinMaxOp(Builder, RK, RdxResult, RdxPart);
+            // createMinMaxOp emits a new select for FP fcmp+select
+            // min/max without MD_prof. Mark its branch weights as
+            // explicitly unknown.
+            if (auto *NewSI = dyn_cast<SelectInst>(RdxResult))
+              setExplicitlyUnknownBranchWeightsIfProfiled(*NewSI, DEBUG_TYPE);
----------------
madhur13490 wrote:

That sounds good to me. Done!

https://github.com/llvm/llvm-project/pull/201010


More information about the llvm-commits mailing list