OSDN Git Service

Transforms: lower fadd and fsub atomicrmw instructions
authorSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 23 May 2019 17:03:43 +0000 (17:03 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 23 May 2019 17:03:43 +0000 (17:03 +0000)
`fadd` and `fsub` have recently (r351850) been added as `atomicrmw`
operations. This diff adds lowering cases for them to the LowerAtomic
transform.

Patch by Josh Berdine!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361512 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LowerAtomic.cpp
test/Transforms/LowerAtomic/atomic-load.ll

index f39ca23..e076424 100644 (file)
@@ -86,6 +86,12 @@ static bool LowerAtomicRMWInst(AtomicRMWInst *RMWI) {
     Res = Builder.CreateSelect(Builder.CreateICmpULT(Orig, Val),
                                Orig, Val);
     break;
+  case AtomicRMWInst::FAdd:
+    Res = Builder.CreateFAdd(Orig, Val);
+    break;
+  case AtomicRMWInst::FSub:
+    Res = Builder.CreateFSub(Orig, Val);
+    break;
   }
   Builder.CreateStore(Res, Ptr);
   RMWI->replaceAllUsesWith(Orig);
index e73417f..f4988c2 100644 (file)
@@ -35,3 +35,25 @@ define i8 @min() {
   ret i8 %j
 ; CHECK: ret i8 [[INST]]
 }
+
+define float @fadd() {
+; CHECK-LABEL: @fadd(
+  %i = alloca float
+  %j = atomicrmw fadd float* %i, float 42.0 monotonic
+; CHECK: [[INST:%[a-z0-9]+]] = load
+; CHECK-NEXT: fadd
+; CHECK-NEXT: store
+  ret float %j
+; CHECK: ret float [[INST]]
+}
+
+define float @fsub() {
+; CHECK-LABEL: @fsub(
+  %i = alloca float
+  %j = atomicrmw fsub float* %i, float 42.0 monotonic
+; CHECK: [[INST:%[a-z0-9]+]] = load
+; CHECK-NEXT: fsub
+; CHECK-NEXT: store
+  ret float %j
+; CHECK: ret float [[INST]]
+}