[llvm] r267215 - [unordered] sink unordered stores at end of blocks
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 22 13:53:33 PDT 2016
Author: reames
Date: Fri Apr 22 15:53:32 2016
New Revision: 267215
URL: http://llvm.org/viewvc/llvm-project?rev=267215&view=rev
Log:
[unordered] sink unordered stores at end of blocks
The existing code turned out to be completely correct when auditted. Thus, only minor code changes and adding a couple of tests.
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=267215&r1=267214&r2=267215&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Fri Apr 22 15:53:32 2016
@@ -1193,10 +1193,6 @@ Instruction *InstCombiner::visitStoreIns
if (isa<UndefValue>(Val))
return eraseInstFromFunction(SI);
- // The code below needs to be audited and adjusted for unordered atomics
- if (!SI.isSimple())
- return nullptr;
-
// If this store is the last instruction in the basic block (possibly
// excepting debug info instructions), and if the block ends with an
// unconditional branch, try to move it to the successor block.
@@ -1222,6 +1218,9 @@ Instruction *InstCombiner::visitStoreIns
/// into a phi node with a store in the successor.
///
bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) {
+ assert(SI.isUnordered() &&
+ "this code has not been auditted for volatile or ordered store case");
+
BasicBlock *StoreBB = SI.getParent();
// Check to see if the successor block has exactly two incoming edges. If
Modified: llvm/trunk/test/Transforms/InstCombine/atomic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/atomic.ll?rev=267215&r1=267214&r2=267215&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/atomic.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/atomic.ll Fri Apr 22 15:53:32 2016
@@ -211,3 +211,37 @@ define i32 @test21(i32** %p, i8* %v) {
store atomic i32* %cast, i32** %p monotonic, align 4
ret i32 0
}
+
+define i32 @test22(i1 %cnd) {
+; CHECK-LABEL: define i32 @test22(
+; CHECK: [[PHI:%.*]] = phi i32
+; CHECK: store atomic i32 [[PHI]], i32* @a unordered, align 4
+ br i1 %cnd, label %block1, label %block2
+
+block1:
+ store atomic i32 1, i32* @a unordered, align 4
+ br label %merge
+block2:
+ store atomic i32 2, i32* @a unordered, align 4
+ br label %merge
+
+merge:
+ ret i32 0
+}
+
+; TODO: probably also legal here
+define i32 @test23(i1 %cnd) {
+; CHECK-LABEL: define i32 @test23(
+; CHECK: br i1 %cnd, label %block1, label %block2
+ br i1 %cnd, label %block1, label %block2
+
+block1:
+ store atomic i32 1, i32* @a monotonic, align 4
+ br label %merge
+block2:
+ store atomic i32 2, i32* @a monotonic, align 4
+ br label %merge
+
+merge:
+ ret i32 0
+}
More information about the llvm-commits
mailing list