[PATCH] D58836: [InstCombine] Extend saturating idempotent atomicrmw transform to FP

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 10:28:16 PST 2019


reames created this revision.
reames added a reviewer: jfb.
Herald added subscribers: bollu, mcrosier.

I'm assuming that the nan propogation logic for InstructonSimplify's handling of fadd and fsub is correct, and applying the same to atomicrmw.


https://reviews.llvm.org/D58836

Files:
  lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp
  test/Transforms/InstCombine/atomicrmw.ll


Index: test/Transforms/InstCombine/atomicrmw.ll
===================================================================
--- test/Transforms/InstCombine/atomicrmw.ll
+++ test/Transforms/InstCombine/atomicrmw.ll
@@ -214,7 +214,7 @@
 }
 
 ; CHECK-LABEL: sat_fadd_nan
-; CHECK-NEXT: %res = atomicrmw fadd double* %addr, double 0x7FF00000FFFFFFFF release
+; CHECK-NEXT: %res = atomicrmw xchg double* %addr, double 0x7FF00000FFFFFFFF release
 ; CHECK-NEXT: ret double %res
 define double @sat_fadd_nan(double* %addr) {
   %res = atomicrmw fadd double* %addr, double 0x7FF00000FFFFFFFF release
@@ -222,7 +222,7 @@
 }
 
 ; CHECK-LABEL: sat_fsub_nan
-; CHECK-NEXT: %res = atomicrmw fsub double* %addr, double 0x7FF00000FFFFFFFF release
+; CHECK-NEXT: %res = atomicrmw xchg double* %addr, double 0x7FF00000FFFFFFFF release
 ; CHECK-NEXT: ret double %res
 define double @sat_fsub_nan(double* %addr) {
   %res = atomicrmw fsub double* %addr, double 0x7FF00000FFFFFFFF release
@@ -230,7 +230,7 @@
 }
 
 ; CHECK-LABEL: sat_fsub_nan_unused
-; CHECK-NEXT: atomicrmw fsub double* %addr, double 0x7FF00000FFFFFFFF monotonic
+; CHECK-NEXT: store atomic double 0x7FF00000FFFFFFFF, double* %addr monotonic, align 8
 ; CHECK-NEXT: ret void
 define void @sat_fsub_nan_unused(double* %addr) {
   atomicrmw fsub double* %addr, double 0x7FF00000FFFFFFFF monotonic
Index: lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp
+++ lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp
@@ -59,6 +59,15 @@
 /// Return true if the given instruction always produces a value in memory
 /// equivelent to its value operand.
 bool isSaturating(AtomicRMWInst& RMWI) {
+  if (auto CF = dyn_cast<ConstantFP>(RMWI.getValOperand()))
+    switch(RMWI.getOperation()) {
+    case AtomicRMWInst::FAdd:
+    case AtomicRMWInst::FSub:
+      return CF->isNaN();
+    default:
+      return false;
+    };
+
   auto C = dyn_cast<ConstantInt>(RMWI.getValOperand());
   if(!C)
     return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58836.188940.patch
Type: text/x-patch
Size: 2064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190301/610de3b6/attachment.bin>


More information about the llvm-commits mailing list