[llvm] 5dd5ddc - [AMDGPU] Skip building some IR if it won't be used. NFC.

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 19 04:38:02 PDT 2021


Author: Jay Foad
Date: 2021-03-19T11:36:14Z
New Revision: 5dd5ddcb41509dee9d830beaaee538e83fde8dff

URL: https://github.com/llvm/llvm-project/commit/5dd5ddcb41509dee9d830beaaee538e83fde8dff
DIFF: https://github.com/llvm/llvm-project/commit/5dd5ddcb41509dee9d830beaaee538e83fde8dff.diff

LOG: [AMDGPU] Skip building some IR if it won't be used. NFC.

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
index 1b98eb04e0d8..34a7cb5a72a8 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
@@ -478,6 +478,8 @@ void AMDGPUAtomicOptimizer::optimizeAtomic(Instruction &I,
   Value *ExclScan = nullptr;
   Value *NewV = nullptr;
 
+  const bool NeedResult = !I.use_empty();
+
   // If we have a divergent value in each lane, we need to combine the value
   // using DPP.
   if (ValDivergent) {
@@ -488,7 +490,8 @@ void AMDGPUAtomicOptimizer::optimizeAtomic(Instruction &I,
     const AtomicRMWInst::BinOp ScanOp =
         Op == AtomicRMWInst::Sub ? AtomicRMWInst::Add : Op;
     NewV = buildScan(B, ScanOp, NewV, Identity);
-    ExclScan = buildShiftRight(B, NewV, Identity);
+    if (NeedResult)
+      ExclScan = buildShiftRight(B, NewV, Identity);
 
     // Read the value from the last lane, which has accumlated the values of
     // each active lane in the wavefront. This will be our new value which we
@@ -581,7 +584,6 @@ void AMDGPUAtomicOptimizer::optimizeAtomic(Instruction &I,
   // original instruction.
   B.SetInsertPoint(&I);
 
-  const bool NeedResult = !I.use_empty();
   if (NeedResult) {
     // Create a PHI node to get our new atomic result into the exit block.
     PHINode *const PHI = B.CreatePHI(Ty, 2);


        


More information about the llvm-commits mailing list