[llvm] [InstCombine] Combine interleaved PHI reduction chains. (PR #143878)

Ricardo Jesus via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 13 01:32:27 PDT 2025


================
@@ -989,6 +990,165 @@ 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
+/// =>
+///   %phi_combined = phi [init_combined, %BB1], [%op_combined, %BB2]
+///   %rdx_combined = binop %phi_combined, constant_combined
+///
+/// For now, we require init1, init2, constant1 and constant2 to be constants.
+Instruction *InstCombinerImpl::foldPHIReduction(PHINode &PN) {
----------------
rj-jesus wrote:

Thanks, I've raised #144031 to add the missing opcodes. If you'd like me to also handle binary intrinsics in the same PR, please just let me know. :)

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


More information about the llvm-commits mailing list