[llvm] r290738 - [LICM] When promoting scalars, allow inserting stores to thread-local allocas.
Michael Kuperstein via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 29 17:03:17 PST 2016
Author: mkuper
Date: Thu Dec 29 19:03:17 2016
New Revision: 290738
URL: http://llvm.org/viewvc/llvm-project?rev=290738&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Transforms/Scalar/LICM.cpp
llvm/trunk/test/Transforms/LICM/promote-tls.ll
Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=290738&r1=290737&r2=290738&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Thu Dec 29 19:03:17 2016
@@ -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.
Modified: llvm/trunk/test/Transforms/LICM/promote-tls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/promote-tls.ll?rev=290738&r1=290737&r2=290738&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LICM/promote-tls.ll (original)
+++ llvm/trunk/test/Transforms/LICM/promote-tls.ll Thu Dec 29 19:03:17 2016
@@ -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:
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:
; 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:
%split = phi i32* [ %addr, %for.body ]
ret i32* null
}
-
More information about the llvm-commits
mailing list