]> granicus.if.org Git - llvm/commitdiff
[GVN] Handle unordered atomics in cross block FRE
authorPhilip Reames <listmail@philipreames.com>
Fri, 6 May 2016 18:46:45 +0000 (18:46 +0000)
committerPhilip Reames <listmail@philipreames.com>
Fri, 6 May 2016 18:46:45 +0000 (18:46 +0000)
You'll note there are essentially no code changes here.  Cross block FRE heavily reuses code from the block local FRE.  All of the tricky parts were done as part of the previous patch and the refactoring that removed the original code duplication.

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

lib/Transforms/Scalar/GVN.cpp
test/Transforms/GVN/atomic.ll

index 116dc69b372b242a03ec87b3799861e18549c8b3..7e937bf954a7e22973e2f4887b7bf7eb2145e2c4 100644 (file)
@@ -1598,11 +1598,6 @@ bool GVN::processNonLocalLoad(LoadInst *LI) {
   if (LI->getParent()->getParent()->hasFnAttribute(Attribute::SanitizeAddress))
     return false;
 
-  // This code hasn't been audited for atomic, ordered, or volatile memory
-  // access.
-  if (!LI->isSimple())
-    return false;
-
   // Step 1: Find the non-local dependencies of the load.
   LoadDepVect Deps;
   MD->getNonLocalPointerDependency(LI, Deps);
@@ -1669,6 +1664,11 @@ bool GVN::processNonLocalLoad(LoadInst *LI) {
     return true;
   }
 
+  // This code hasn't been audited for atomic, ordered, or volatile memory
+  // access.
+  if (!LI->isSimple())
+    return false;
+
   // Step 4: Eliminate partial redundancy.
   if (!EnablePRE || !EnableLoadPRE)
     return false;
index 4429e9bbad04950aec514c8bcc6272f5c01102de..f8a70140cc3cd4ae682057ebd0af12a2b63784bf 100644 (file)
@@ -337,3 +337,58 @@ define i64 @narrow2(i32* %P1) {
   ret i64 %res
 }
 
+; Note: The cross block FRE testing is deliberately light.  All of the tricky
+; bits of legality are shared code with the block-local FRE above.  These
+; are here only to show that we haven't obviously broken anything.
+
+; unordered atomic to unordered atomic
+define i32 @non_local_fre(i32* %P1) {
+; CHECK-LABEL: @non_local_fre(
+; CHECK: load atomic i32, i32* %P1
+; CHECK: ret i32 0
+; CHECK: ret i32 0
+  %a = load atomic i32, i32* %P1 unordered, align 4
+  %cmp = icmp eq i32 %a, 0
+  br i1 %cmp, label %early, label %next
+early:
+  ret i32 %a
+next:
+  %b = load atomic i32, i32* %P1 unordered, align 4
+  %res = sub i32 %a, %b
+  ret i32 %res
+}
+
+; unordered atomic to non-atomic
+define i32 @non_local_fre2(i32* %P1) {
+; CHECK-LABEL: @non_local_fre2(
+; CHECK: load atomic i32, i32* %P1
+; CHECK: ret i32 0
+; CHECK: ret i32 0
+  %a = load atomic i32, i32* %P1 unordered, align 4
+  %cmp = icmp eq i32 %a, 0
+  br i1 %cmp, label %early, label %next
+early:
+  ret i32 %a
+next:
+  %b = load i32, i32* %P1
+  %res = sub i32 %a, %b
+  ret i32 %res
+}
+
+; Can't forward ordered atomics.
+define i32 @non_local_fre3(i32* %P1) {
+; CHECK-LABEL: @non_local_fre3(
+; CHECK: load atomic i32, i32* %P1 acquire
+; CHECK: ret i32 0
+; CHECK: load atomic i32, i32* %P1 acquire
+; CHECK: ret i32 %res
+  %a = load atomic i32, i32* %P1 acquire, align 4
+  %cmp = icmp eq i32 %a, 0
+  br i1 %cmp, label %early, label %next
+early:
+  ret i32 %a
+next:
+  %b = load atomic i32, i32* %P1 acquire, align 4
+  %res = sub i32 %a, %b
+  ret i32 %res
+}