mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-08 21:10:31 +00:00
[LICM] When promoting scalars, allow inserting stores to thread-local allocas.
This is similar to the allocfn case - if an alloca is not captured, then it's necessarily thread-local. Differential Revision: https://reviews.llvm.org/D28170 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290738 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ddd3bb716c
commit
4f67d55a96
@ -1034,7 +1034,8 @@ bool llvm::promoteLoopAccessesToScalars(
|
||||
if (!SafeToInsertStore) {
|
||||
Value *Object = GetUnderlyingObject(SomePtr, MDL);
|
||||
SafeToInsertStore =
|
||||
isAllocLikeFn(Object, TLI) && !PointerMayBeCaptured(Object, true, true);
|
||||
(isAllocLikeFn(Object, TLI) || isa<AllocaInst>(Object)) &&
|
||||
!PointerMayBeCaptured(Object, true, true);
|
||||
}
|
||||
|
||||
// If we've still failed to prove we can sink the store, give up.
|
||||
|
@ -12,6 +12,7 @@ target triple = "x86_64-linux-generic"
|
||||
declare i8* @malloc(i64)
|
||||
|
||||
; Exercise the TLS case
|
||||
; CHECK-LABEL: @test
|
||||
define i32* @test(i32 %n) {
|
||||
entry:
|
||||
;; ignore the required null check for simplicity
|
||||
@ -49,9 +50,48 @@ for.cond.for.end_crit_edge: ; preds = %for.body
|
||||
ret i32* null
|
||||
}
|
||||
|
||||
; Stack allocations can also be thread-local
|
||||
; CHECK-LABEL: @test2
|
||||
define i32* @test2(i32 %n) {
|
||||
entry:
|
||||
%mem = alloca i8, i32 16
|
||||
%addr = bitcast i8* %mem to i32*
|
||||
br label %for.body.lr.ph
|
||||
|
||||
for.body.lr.ph: ; preds = %entry
|
||||
br label %for.header
|
||||
|
||||
for.header:
|
||||
%i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
|
||||
%old = load i32, i32* %addr, align 4
|
||||
; deliberate impossible to analyze branch
|
||||
%guard = load atomic i8*, i8** @p monotonic, align 8
|
||||
%exitcmp = icmp eq i8* %guard, null
|
||||
br i1 %exitcmp, label %for.body, label %early-exit
|
||||
|
||||
early-exit:
|
||||
; CHECK-LABEL: early-exit:
|
||||
; CHECK: store i32 %new1.lcssa, i32* %addr, align 1
|
||||
ret i32* null
|
||||
|
||||
for.body:
|
||||
%new = add i32 %old, 1
|
||||
store i32 %new, i32* %addr, align 4
|
||||
%inc = add nsw i32 %i.02, 1
|
||||
%cmp = icmp slt i32 %inc, %n
|
||||
br i1 %cmp, label %for.header, label %for.cond.for.end_crit_edge
|
||||
|
||||
for.cond.for.end_crit_edge: ; preds = %for.body
|
||||
; CHECK-LABEL: for.cond.for.end_crit_edge:
|
||||
; CHECK: store i32 %new.lcssa, i32* %addr, align 1
|
||||
%split = phi i32* [ %addr, %for.body ]
|
||||
ret i32* null
|
||||
}
|
||||
|
||||
declare i8* @not_malloc(i64)
|
||||
|
||||
; Negative test - not TLS
|
||||
; CHECK-LABEL: @test_neg
|
||||
define i32* @test_neg(i32 %n) {
|
||||
entry:
|
||||
;; ignore the required null check for simplicity
|
||||
@ -93,6 +133,7 @@ for.cond.for.end_crit_edge: ; preds = %for.body
|
||||
|
||||
; Negative test - can't speculate load since branch
|
||||
; may control alignment
|
||||
; CHECK-LABEL: @test_neg2
|
||||
define i32* @test_neg2(i32 %n) {
|
||||
entry:
|
||||
;; ignore the required null check for simplicity
|
||||
@ -131,4 +172,3 @@ for.cond.for.end_crit_edge: ; preds = %for.body
|
||||
%split = phi i32* [ %addr, %for.body ]
|
||||
ret i32* null
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user