[llvm] [AMDGPU] Fix scan of atomicFSub in AtomicOptimizer. (PR #66082)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 06:15:16 PDT 2023


================
@@ -754,8 +754,15 @@ void AMDGPUAtomicOptimizerImpl::optimizeAtomic(Instruction &I,
   // If we have a divergent value in each lane, we need to combine the value
   // using DPP.
   if (ValDivergent) {
-    const AtomicRMWInst::BinOp ScanOp =
-        Op == AtomicRMWInst::Sub ? AtomicRMWInst::Add : Op;
+    // For atomic sub, perform scan with add operation and allow one lane to substract the reduced value later.
+    AtomicRMWInst::BinOp ScanOp;
+    if(Op == AtomicRMWInst::Sub ) {
+      ScanOp = AtomicRMWInst::Add;
+    } else if (Op == AtomicRMWInst::FSub) {
+      ScanOp = AtomicRMWInst::FAdd;
+    } else {
+      ScanOp = Op;
----------------
arsenm wrote:

Just initialize ScanOp to Op?

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


More information about the llvm-commits mailing list