[llvm] r267023 - [instcombine][unordered] Extend load(select) transform to handle unordered loads
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 21 11:00:14 PDT 2016
Author: reames
Date: Thu Apr 21 12:59:40 2016
New Revision: 267023
URL: http://llvm.org/viewvc/llvm-project?rev=267023&view=rev
Log:
[instcombine][unordered] Extend load(select) transform to handle unordered loads
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=267023&r1=267022&r2=267023&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Thu Apr 21 12:59:40 2016
@@ -867,10 +867,6 @@ Instruction *InstCombiner::visitLoadInst
return replaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
- // TODO: The transform below needs updated for unordered loads
- if (!LI.isSimple())
- return nullptr;
-
if (Op->hasOneUse()) {
// Change select and PHI nodes to select values instead of addresses: this
// helps alias analysis out a lot, allows many others simplifications, and
@@ -891,8 +887,11 @@ Instruction *InstCombiner::visitLoadInst
SI->getOperand(1)->getName()+".val");
LoadInst *V2 = Builder->CreateLoad(SI->getOperand(2),
SI->getOperand(2)->getName()+".val");
+ assert(LI.isUnordered() && "implied by above");
V1->setAlignment(Align);
+ V1->setAtomic(LI.getOrdering(), LI.getSynchScope());
V2->setAlignment(Align);
+ V2->setAtomic(LI.getOrdering(), LI.getSynchScope());
return SelectInst::Create(SI->getCondition(), V1, V2);
}
Modified: llvm/trunk/test/Transforms/InstCombine/atomic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/atomic.ll?rev=267023&r1=267022&r2=267023&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/atomic.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/atomic.ll Thu Apr 21 12:59:40 2016
@@ -143,4 +143,32 @@ define i32 @test14() {
ret i32 0
}
+ at a = external global i32
+ at b = external global i32
+define i32 @test15(i1 %cnd) {
+; CHECK-LABEL: define i32 @test15(
+; CHECK: load atomic i32, i32* @a unordered, align 4
+; CHECK: load atomic i32, i32* @b unordered, align 4
+ %addr = select i1 %cnd, i32* @a, i32* @b
+ %x = load atomic i32, i32* %addr unordered, align 4
+ ret i32 %x
+}
+
+; FIXME: This would be legal to transform
+define i32 @test16(i1 %cnd) {
+; CHECK-LABEL: define i32 @test16(
+; CHECK: load atomic i32, i32* %addr monotonic, align 4
+ %addr = select i1 %cnd, i32* @a, i32* @b
+ %x = load atomic i32, i32* %addr monotonic, align 4
+ ret i32 %x
+}
+
+; FIXME: This would be legal to transform
+define i32 @test17(i1 %cnd) {
+; CHECK-LABEL: define i32 @test17(
+; CHECK: load atomic i32, i32* %addr seq_cst, align 4
+ %addr = select i1 %cnd, i32* @a, i32* @b
+ %x = load atomic i32, i32* %addr seq_cst, align 4
+ ret i32 %x
+}
More information about the llvm-commits
mailing list