[llvm] [InstCombine] Combine interleaved PHI reduction chains. (PR #143878)
Ricardo Jesus via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 24 02:39:55 PDT 2025
================
@@ -996,6 +997,150 @@ Instruction *InstCombinerImpl::foldPHIArgOpIntoPHI(PHINode &PN) {
return NewCI;
}
+/// Try to fold reduction ops interleaved through two PHIs to a single PHI.
+///
+/// For example, combine:
+/// %phi1 = phi [init1, %BB1], [%op1, %BB2]
+/// %phi2 = phi [init2, %BB1], [%op2, %BB2]
+/// %op1 = binop %phi1, constant1
+/// %op2 = binop %phi2, constant2
+/// %rdx = binop %op1, %op2
----------------
rj-jesus wrote:
Hi @nikic, @dtcxzyw, I apologise for the delayed response. I was out of the office for most of last week.
> Why does the pattern start matching at one of the phi nodes rather than at %rdx?
Given that I was specifically looking for sequences of interleaved recurrences, it seemed that starting at one of the phi nodes and working down from there would potentially allow bailing out sooner than if the match had started from `%rdx`. But I'm not precious about it, I'm happy to start the match from `%rdx` and/or move the pattern elsewhere if that's more appropriate.
Would it be preferable to move the pattern to a method similar to `foldBinopWithPhiOperands` and start the match from `%rdx`? Or do you have something else in mind? :)
https://github.com/llvm/llvm-project/pull/143878
More information about the llvm-commits
mailing list