[llvm] r267006 - [instcombine][unordered] Implement *-load forwarding for unordered atomics
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 21 10:03:33 PDT 2016
Author: reames
Date: Thu Apr 21 12:03:33 2016
New Revision: 267006
URL: http://llvm.org/viewvc/llvm-project?rev=267006&view=rev
Log:
[instcombine][unordered] Implement *-load forwarding for unordered atomics
This builds on 266999 which made FindAvailableValue do the right thing. Tests included show the newly enabled transforms and those which disabled either due to conservatism or correctness requirements.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/trunk/test/Transforms/InstCombine/atomic.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=267006&r1=267005&r2=267006&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Thu Apr 21 12:03:33 2016
@@ -809,10 +809,6 @@ Instruction *InstCombiner::visitLoadInst
return &LI;
}
- // None of the following transforms are legal for volatile/atomic loads.
- // FIXME: Some of it is okay for atomic loads; needs refactoring.
- if (!LI.isSimple()) return nullptr;
-
if (Instruction *Res = unpackLoadToAggregate(*this, LI))
return Res;
@@ -840,6 +836,10 @@ Instruction *InstCombiner::visitLoadInst
LI.getName() + ".cast"));
}
+ // None of the following transforms are legal for volatile/atomic loads.
+ // FIXME: Some of it is okay for atomic loads; needs refactoring.
+ if (!LI.isSimple()) return nullptr;
+
// load(gep null, ...) -> unreachable
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) {
const Value *GEPI0 = GEPI->getOperand(0);
Modified: llvm/trunk/test/Transforms/InstCombine/atomic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/atomic.ll?rev=267006&r1=267005&r2=267006&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/atomic.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/atomic.ll Thu Apr 21 12:03:33 2016
@@ -37,11 +37,11 @@ define i32 @test3(i32* %p) {
ret i32 %z
}
-; FIXME: Forwarding from a stronger atomic is fine
+; Forwarding from a stronger ordered atomic is fine
define i32 @test4(i32* %p) {
; CHECK-LABEL: define i32 @test4(
; CHECK: %x = load atomic i32, i32* %p seq_cst, align 4
-; CHECK: %y = load atomic i32, i32* %p unordered, align 4
+; CHECK: shl i32 %x, 1
%x = load atomic i32, i32* %p seq_cst, align 4
%y = load atomic i32, i32* %p unordered, align 4
%z = add i32 %x, %y
@@ -59,4 +59,37 @@ define i32 @test5(i32* %p) {
%z = add i32 %x, %y
ret i32 %z
}
+
+; Forwarding atomic to atomic is fine
+define i32 @test6(i32* %p) {
+; CHECK-LABEL: define i32 @test6(
+; CHECK: %x = load atomic i32, i32* %p unordered, align 4
+; CHECK: shl i32 %x, 1
+ %x = load atomic i32, i32* %p unordered, align 4
+ %y = load atomic i32, i32* %p unordered, align 4
+ %z = add i32 %x, %y
+ ret i32 %z
+}
+
+; FIXME: we currently don't do anything for monotonic
+define i32 @test7(i32* %p) {
+; CHECK-LABEL: define i32 @test7(
+; CHECK: %x = load atomic i32, i32* %p seq_cst, align 4
+; CHECK: %y = load atomic i32, i32* %p monotonic, align 4
+ %x = load atomic i32, i32* %p seq_cst, align 4
+ %y = load atomic i32, i32* %p monotonic, align 4
+ %z = add i32 %x, %y
+ ret i32 %z
+}
+
+; FIXME: We could forward in racy code
+define i32 @test8(i32* %p) {
+; CHECK-LABEL: define i32 @test8(
+; CHECK: %x = load atomic i32, i32* %p seq_cst, align 4
+; CHECK: %y = load atomic i32, i32* %p acquire, align 4
+ %x = load atomic i32, i32* %p seq_cst, align 4
+ %y = load atomic i32, i32* %p acquire, align 4
+ %z = add i32 %x, %y
+ ret i32 %z
+}
More information about the llvm-commits
mailing list