[llvm] [AMDGPU] Add wave reduce intrinsics for double types - 1 (PR #170811)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 8 23:44:26 PST 2026


================
@@ -5968,6 +5958,60 @@ static MachineBasicBlock *lowerWaveReduce(MachineInstr &MI,
                              .addReg(Accumulator->getOperand(0).getReg());
         break;
       }
+      case AMDGPU::V_MIN_F64_e64:
+      case AMDGPU::V_MAX_F64_e64: {
+        const TargetRegisterClass *VregRC = TRI->getVGPR64Class();
+        const TargetRegisterClass *VregSubRC =
+            TRI->getSubRegisterClass(VregRC, AMDGPU::sub0);
+        Register AccumulatorVReg = MRI.createVirtualRegister(VregRC);
+        Register DstVreg = MRI.createVirtualRegister(VregRC);
+        Register LaneValLo =
+            MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
+        Register LaneValHi =
+            MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
+        BuildMI(*ComputeLoop, I, DL, TII->get(AMDGPU::V_MOV_B64_PSEUDO),
+                AccumulatorVReg)
+            .addReg(Accumulator->getOperand(0).getReg());
+        if (ST.getGeneration() == AMDGPUSubtarget::Generation::GFX12) {
+          switch (Opc) {
+          case AMDGPU::V_MIN_F64_e64:
+            Opc = AMDGPU::V_MIN_NUM_F64_e64;
+            break;
+          case AMDGPU::V_MAX_F64_e64:
+            Opc = AMDGPU::V_MAX_NUM_F64_e64;
+            break;
+          }
----------------
easyonaadit wrote:

> It doesn't make sense to put this inside the loop, the extra quiet would only be necessary for the first iteration

I think canonicalizing before each comparison would be better.
Suppose `<1, 0, snan>` reduced from left to right:
IEEE=False returns 0
IEEE=True returns qnan
IEEE=true if canonicalized before each comparison returns 0

> Can you put that into the AMDGPUUsage description?

Yupp sure.

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


More information about the llvm-commits mailing list