[llvm] [AMDGPU]Refactor `lowerWaveReduce` for maintainability (PR #189223)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 02:52:38 PDT 2026


================
@@ -5617,60 +5669,79 @@ static uint64_t getIdentityValueFor64BitWaveReduction(unsigned Opc) {
   case AMDGPU::V_ADD_F64_pseudo_e64:
     return 0x8000000000000000; // -0.0
   default:
-    llvm_unreachable(
-        "Unexpected opcode in getIdentityValueFor64BitWaveReduction");
-  }
-}
-
-static bool is32bitWaveReduceOperation(unsigned Opc) {
-  return Opc == AMDGPU::S_MIN_U32 || Opc == AMDGPU::S_MIN_I32 ||
-         Opc == AMDGPU::S_MAX_U32 || Opc == AMDGPU::S_MAX_I32 ||
-         Opc == AMDGPU::S_ADD_I32 || Opc == AMDGPU::S_SUB_I32 ||
-         Opc == AMDGPU::S_AND_B32 || Opc == AMDGPU::S_OR_B32 ||
-         Opc == AMDGPU::S_XOR_B32 || Opc == AMDGPU::V_MIN_F32_e64 ||
-         Opc == AMDGPU::V_MAX_F32_e64 || Opc == AMDGPU::V_ADD_F32_e64 ||
-         Opc == AMDGPU::V_SUB_F32_e64;
-}
-
-static bool isFloatingPointWaveReduceOperation(unsigned Opc) {
-  return Opc == AMDGPU::V_MIN_F32_e64 || Opc == AMDGPU::V_MAX_F32_e64 ||
-         Opc == AMDGPU::V_ADD_F32_e64 || Opc == AMDGPU::V_SUB_F32_e64 ||
-         Opc == AMDGPU::V_MIN_F64_e64 || Opc == AMDGPU::V_MAX_F64_e64 ||
-         Opc == AMDGPU::V_MIN_NUM_F64_e64 || Opc == AMDGPU::V_MAX_NUM_F64_e64 ||
-         Opc == AMDGPU::V_ADD_F64_e64 || Opc == AMDGPU::V_ADD_F64_pseudo_e64;
-}
-
-static unsigned getDPPOpcForWaveReduction(unsigned Opc,
-                                          const GCNSubtarget &ST) {
+    llvm_unreachable("Unexpected opcode in getIdentityValueForWaveReduction");
+  }
+}
+
+static std::tuple<bool, bool> ClassifyWaveReductionOp(unsigned Opc) {
----------------
jmmartinez wrote:

I find that having a function that does a single thing (`is32bitWaveReduceOperation/isFloatingPointWaveReduceOperation`) is better than one that does multiple things `ClassifyWaveReductionOp`.

It'd be fine if we were saving some redundant computations, but we're not.

Besides, it's awkward that to understand what the tuple that gets returned is, we have to check other calls or the function implementation. With the old methods it's obvious from the name.

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


More information about the llvm-commits mailing list