OSDN Git Service

SelectionDAG: accommodate atomic floating stores.
authorTim Northover <tnorthover@apple.com>
Fri, 10 May 2019 11:23:04 +0000 (11:23 +0000)
committerTim Northover <tnorthover@apple.com>
Fri, 10 May 2019 11:23:04 +0000 (11:23 +0000)
We were applying a pointer truncation to floating types, which crashed LLVM.
That is Not A Good Thing(TM).

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

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
test/CodeGen/NVPTX/load-store.ll

index 75349cb..e58b0d2 100644 (file)
@@ -4717,7 +4717,10 @@ void SelectionDAGBuilder::visitAtomicStore(const StoreInst &I) {
                             MemVT.getStoreSize(), I.getAlignment(), AAMDNodes(),
                             nullptr, SSID, Ordering);
 
-  SDValue Val = DAG.getPtrExtOrTrunc(getValue(I.getValueOperand()), dl, MemVT);
+  SDValue Val = getValue(I.getValueOperand());
+  if (Val.getValueType() != MemVT)
+    Val = DAG.getPtrExtOrTrunc(Val, dl, MemVT);
+
   SDValue OutChain = DAG.getAtomic(ISD::ATOMIC_STORE, dl, MemVT, InChain,
                                    getValue(I.getPointerOperand()), Val, MMO);
 
index 03b0109..a3fb172 100644 (file)
@@ -59,7 +59,7 @@ define void @volatile(i8* %a, i16* %b, i32* %c, i64* %d) local_unnamed_addr {
 }
 
 ; CHECK-LABEL: monotonic
-define void @monotonic(i8* %a, i16* %b, i32* %c, i64* %d) local_unnamed_addr {
+define void @monotonic(i8* %a, i16* %b, i32* %c, i64* %d, float* %e) local_unnamed_addr {
   ; CHECK: ld.volatile.u8 %rs{{[0-9]+}}, [%rd{{[0-9]+}}]
   %a.load = load atomic i8, i8* %a monotonic, align 1
   %a.add = add i8 %a.load, 1
@@ -84,5 +84,11 @@ define void @monotonic(i8* %a, i16* %b, i32* %c, i64* %d) local_unnamed_addr {
   ; CHECK: st.volatile.u64 [%rd{{[0-9]+}}], %rd{{[0-9]+}}
   store atomic i64 %d.add, i64* %d monotonic, align 8
 
+  ; CHECK: ld.volatile.f32 %f{{[0-9]+}}, [%rd{{[0-9]+}}]
+  %e.load = load atomic float, float* %e monotonic, align 4
+  %e.add = fadd float %e.load, 1.0
+  ; CHECK: st.volatile.f32 [%rd{{[0-9]+}}], %f{{[0-9]+}}
+  store atomic float %e.add, float* %e monotonic, align 4
+
   ret void
 }