mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 20:26:07 +00:00
Atomic load/store support in LICM.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137648 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -126,8 +126,6 @@ void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry,
|
|||||||
void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) {
|
void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) {
|
||||||
UnknownInsts.push_back(I);
|
UnknownInsts.push_back(I);
|
||||||
|
|
||||||
if (!I->mayReadOrWriteMemory())
|
|
||||||
return;
|
|
||||||
if (!I->mayWriteToMemory()) {
|
if (!I->mayWriteToMemory()) {
|
||||||
AliasTy = MayAlias;
|
AliasTy = MayAlias;
|
||||||
AccessTy |= Refs;
|
AccessTy |= Refs;
|
||||||
@@ -297,22 +295,28 @@ bool AliasSetTracker::add(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo) {
|
|||||||
|
|
||||||
|
|
||||||
bool AliasSetTracker::add(LoadInst *LI) {
|
bool AliasSetTracker::add(LoadInst *LI) {
|
||||||
|
if (LI->getOrdering() > Monotonic) return addUnknown(LI);
|
||||||
|
AliasSet::AccessType ATy = AliasSet::Refs;
|
||||||
|
if (!LI->isUnordered()) ATy = AliasSet::ModRef;
|
||||||
bool NewPtr;
|
bool NewPtr;
|
||||||
AliasSet &AS = addPointer(LI->getOperand(0),
|
AliasSet &AS = addPointer(LI->getOperand(0),
|
||||||
AA.getTypeStoreSize(LI->getType()),
|
AA.getTypeStoreSize(LI->getType()),
|
||||||
LI->getMetadata(LLVMContext::MD_tbaa),
|
LI->getMetadata(LLVMContext::MD_tbaa),
|
||||||
AliasSet::Refs, NewPtr);
|
ATy, NewPtr);
|
||||||
if (LI->isVolatile()) AS.setVolatile();
|
if (LI->isVolatile()) AS.setVolatile();
|
||||||
return NewPtr;
|
return NewPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AliasSetTracker::add(StoreInst *SI) {
|
bool AliasSetTracker::add(StoreInst *SI) {
|
||||||
|
if (SI->getOrdering() > Monotonic) return addUnknown(SI);
|
||||||
|
AliasSet::AccessType ATy = AliasSet::Mods;
|
||||||
|
if (!SI->isUnordered()) ATy = AliasSet::ModRef;
|
||||||
bool NewPtr;
|
bool NewPtr;
|
||||||
Value *Val = SI->getOperand(0);
|
Value *Val = SI->getOperand(0);
|
||||||
AliasSet &AS = addPointer(SI->getOperand(1),
|
AliasSet &AS = addPointer(SI->getOperand(1),
|
||||||
AA.getTypeStoreSize(Val->getType()),
|
AA.getTypeStoreSize(Val->getType()),
|
||||||
SI->getMetadata(LLVMContext::MD_tbaa),
|
SI->getMetadata(LLVMContext::MD_tbaa),
|
||||||
AliasSet::Mods, NewPtr);
|
ATy, NewPtr);
|
||||||
if (SI->isVolatile()) AS.setVolatile();
|
if (SI->isVolatile()) AS.setVolatile();
|
||||||
return NewPtr;
|
return NewPtr;
|
||||||
}
|
}
|
||||||
|
@@ -362,8 +362,8 @@ void LICM::HoistRegion(DomTreeNode *N) {
|
|||||||
bool LICM::canSinkOrHoistInst(Instruction &I) {
|
bool LICM::canSinkOrHoistInst(Instruction &I) {
|
||||||
// Loads have extra constraints we have to verify before we can hoist them.
|
// Loads have extra constraints we have to verify before we can hoist them.
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
|
if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
|
||||||
if (LI->isVolatile())
|
if (!LI->isUnordered())
|
||||||
return false; // Don't hoist volatile loads!
|
return false; // Don't hoist volatile/atomic loads!
|
||||||
|
|
||||||
// Loads from constant memory are always safe to move, even if they end up
|
// Loads from constant memory are always safe to move, even if they end up
|
||||||
// in the same alias set as something that ends up being modified.
|
// in the same alias set as something that ends up being modified.
|
||||||
@@ -722,15 +722,18 @@ void LICM::PromoteAliasSet(AliasSet &AS) {
|
|||||||
|
|
||||||
// If there is an non-load/store instruction in the loop, we can't promote
|
// If there is an non-load/store instruction in the loop, we can't promote
|
||||||
// it.
|
// it.
|
||||||
if (isa<LoadInst>(Use)) {
|
if (LoadInst *load = dyn_cast<LoadInst>(Use)) {
|
||||||
assert(!cast<LoadInst>(Use)->isVolatile() && "AST broken");
|
assert(!load->isVolatile() && "AST broken");
|
||||||
|
if (!load->isSimple())
|
||||||
|
return;
|
||||||
} else if (StoreInst *store = dyn_cast<StoreInst>(Use)) {
|
} else if (StoreInst *store = dyn_cast<StoreInst>(Use)) {
|
||||||
// Stores *of* the pointer are not interesting, only stores *to* the
|
// Stores *of* the pointer are not interesting, only stores *to* the
|
||||||
// pointer.
|
// pointer.
|
||||||
if (Use->getOperand(1) != ASIV)
|
if (Use->getOperand(1) != ASIV)
|
||||||
continue;
|
continue;
|
||||||
unsigned InstAlignment = store->getAlignment();
|
assert(!store->isVolatile() && "AST broken");
|
||||||
assert(!cast<StoreInst>(Use)->isVolatile() && "AST broken");
|
if (!store->isSimple())
|
||||||
|
return;
|
||||||
|
|
||||||
// Note that we only check GuaranteedToExecute inside the store case
|
// Note that we only check GuaranteedToExecute inside the store case
|
||||||
// so that we do not introduce stores where they did not exist before
|
// so that we do not introduce stores where they did not exist before
|
||||||
@@ -740,6 +743,7 @@ void LICM::PromoteAliasSet(AliasSet &AS) {
|
|||||||
// restrictive (and performant) alignment and if we are sure this
|
// restrictive (and performant) alignment and if we are sure this
|
||||||
// instruction will be executed, update the alignment.
|
// instruction will be executed, update the alignment.
|
||||||
// Larger is better, with the exception of 0 being the best alignment.
|
// Larger is better, with the exception of 0 being the best alignment.
|
||||||
|
unsigned InstAlignment = store->getAlignment();
|
||||||
if ((InstAlignment > Alignment || InstAlignment == 0)
|
if ((InstAlignment > Alignment || InstAlignment == 0)
|
||||||
&& (Alignment != 0))
|
&& (Alignment != 0))
|
||||||
if (isGuaranteedToExecute(*Use)) {
|
if (isGuaranteedToExecute(*Use)) {
|
||||||
|
79
test/Transforms/LICM/atomics.ll
Normal file
79
test/Transforms/LICM/atomics.ll
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
; RUN: opt < %s -S -basicaa -licm | FileCheck %s
|
||||||
|
|
||||||
|
; Check that we can hoist unordered loads
|
||||||
|
define i32 @test1(i32* nocapture %y) nounwind uwtable ssp {
|
||||||
|
entry:
|
||||||
|
br label %loop
|
||||||
|
|
||||||
|
loop:
|
||||||
|
%i = phi i32 [ %inc, %loop ], [ 0, %entry ]
|
||||||
|
%val = load atomic i32* %y unordered, align 4
|
||||||
|
%inc = add nsw i32 %i, 1
|
||||||
|
%exitcond = icmp eq i32 %inc, %val
|
||||||
|
br i1 %exitcond, label %end, label %loop
|
||||||
|
|
||||||
|
end:
|
||||||
|
ret i32 %val
|
||||||
|
; CHECK: define i32 @test1(
|
||||||
|
; CHECK: load atomic
|
||||||
|
; CHECK-NEXT: br label %loop
|
||||||
|
}
|
||||||
|
|
||||||
|
; Check that we don't sink/hoist monotonic loads
|
||||||
|
; (Strictly speaking, it's not forbidden, but it's supposed to be possible to
|
||||||
|
; use monotonic for spinlock-like constructs.)
|
||||||
|
define i32 @test2(i32* nocapture %y) nounwind uwtable ssp {
|
||||||
|
entry:
|
||||||
|
br label %loop
|
||||||
|
|
||||||
|
loop:
|
||||||
|
%val = load atomic i32* %y monotonic, align 4
|
||||||
|
%exitcond = icmp ne i32 %val, 0
|
||||||
|
br i1 %exitcond, label %end, label %loop
|
||||||
|
|
||||||
|
end:
|
||||||
|
ret i32 %val
|
||||||
|
; CHECK: define i32 @test2(
|
||||||
|
; CHECK: load atomic
|
||||||
|
; CHECK-NEXT: %exitcond = icmp ne
|
||||||
|
; CHECK-NEXT: br i1 %exitcond, label %end, label %loop
|
||||||
|
}
|
||||||
|
|
||||||
|
; Check that we hoist unordered around monotonic.
|
||||||
|
; (The noalias shouldn't be necessary in theory, but LICM isn't quite that
|
||||||
|
; smart yet.)
|
||||||
|
define i32 @test3(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
|
||||||
|
entry:
|
||||||
|
br label %loop
|
||||||
|
|
||||||
|
loop:
|
||||||
|
%vala = load atomic i32* %y monotonic, align 4
|
||||||
|
%valb = load atomic i32* %x unordered, align 4
|
||||||
|
%exitcond = icmp ne i32 %vala, %valb
|
||||||
|
br i1 %exitcond, label %end, label %loop
|
||||||
|
|
||||||
|
end:
|
||||||
|
ret i32 %vala
|
||||||
|
; CHECK: define i32 @test3(
|
||||||
|
; CHECK: load atomic i32* %x unordered
|
||||||
|
; CHECK-NEXT: br label %loop
|
||||||
|
}
|
||||||
|
|
||||||
|
; Don't try to "sink" unordered stores yet; it is legal, but the machinery
|
||||||
|
; isn't there.
|
||||||
|
define i32 @test4(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
|
||||||
|
entry:
|
||||||
|
br label %loop
|
||||||
|
|
||||||
|
loop:
|
||||||
|
%vala = load atomic i32* %y monotonic, align 4
|
||||||
|
store atomic i32 %vala, i32* %x unordered, align 4
|
||||||
|
%exitcond = icmp ne i32 %vala, 0
|
||||||
|
br i1 %exitcond, label %end, label %loop
|
||||||
|
|
||||||
|
end:
|
||||||
|
ret i32 %vala
|
||||||
|
; CHECK: define i32 @test4(
|
||||||
|
; CHECK: load atomic i32* %y monotonic
|
||||||
|
; CHECK-NEXT: store atomic
|
||||||
|
}
|
Reference in New Issue
Block a user