diff options
author | Hideto Ueno <uenoku.tokotoko@gmail.com> | 2019-07-23 08:16:17 +0000 |
---|---|---|
committer | Hideto Ueno <uenoku.tokotoko@gmail.com> | 2019-07-23 08:16:17 +0000 |
commit | 19c07afe17fcacd8fd7d1196df16150be69e0dc9 (patch) | |
tree | 69879ce5227ce765687cca18394378c6533791c5 /llvm/test/Transforms/FunctionAttrs | |
parent | c7e6d14c6c30c6798b14faf2a28e5be642b78ad8 (diff) | |
download | bcm5719-llvm-19c07afe17fcacd8fd7d1196df16150be69e0dc9.tar.gz bcm5719-llvm-19c07afe17fcacd8fd7d1196df16150be69e0dc9.zip |
[Attributor] Deduce "dereferenceable" attribute
Summary:
Deduce dereferenceable attribute in Attributor.
These will be added in a later patch.
* dereferenceable(_or_null)_globally (D61652)
* Deduction based on load instruction (similar to D64258)
Reviewers: jdoerfert, sstefan1
Reviewed By: jdoerfert
Subscribers: hiraditya, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64876
llvm-svn: 366788
Diffstat (limited to 'llvm/test/Transforms/FunctionAttrs')
4 files changed, 66 insertions, 5 deletions
diff --git a/llvm/test/Transforms/FunctionAttrs/arg_nocapture.ll b/llvm/test/Transforms/FunctionAttrs/arg_nocapture.ll index 0bc7053f7ad..eacc9fbe5f7 100644 --- a/llvm/test/Transforms/FunctionAttrs/arg_nocapture.ll +++ b/llvm/test/Transforms/FunctionAttrs/arg_nocapture.ll @@ -88,7 +88,7 @@ entry: ; Other arguments are possible here due to the no-return behavior. ; ; FIXME: no-return missing -; CHECK: define noalias nonnull i32* @srec16(i32* nocapture readnone %a) +; CHECK: define noalias nonnull dereferenceable(4294967295) i32* @srec16(i32* nocapture readnone %a) define i32* @srec16(i32* %a) #0 { entry: %call = call i32* @srec16(i32* %a) diff --git a/llvm/test/Transforms/FunctionAttrs/dereferenceable.ll b/llvm/test/Transforms/FunctionAttrs/dereferenceable.ll new file mode 100644 index 00000000000..16459fc4c42 --- /dev/null +++ b/llvm/test/Transforms/FunctionAttrs/dereferenceable.ll @@ -0,0 +1,52 @@ +; RUN: opt -attributor --attributor-disable=false -S < %s | FileCheck %s --check-prefixes=ATTRIBUTOR + + +; TEST 1 +; take mininimum of return values +; +define i32* @test1(i32* dereferenceable(4), double* dereferenceable(8), i1 zeroext) local_unnamed_addr { +; ATTRIBUTOR: define nonnull dereferenceable(4) i32* @test1(i32* nonnull dereferenceable(4), double* nonnull dereferenceable(8), i1 zeroext) + %4 = bitcast double* %1 to i32* + %5 = select i1 %2, i32* %0, i32* %4 + ret i32* %5 +} + +; TEST 2 +define i32* @test2(i32* dereferenceable_or_null(4), double* dereferenceable(8), i1 zeroext) local_unnamed_addr { +; ATTRIBUTOR: define dereferenceable_or_null(4) i32* @test2(i32* dereferenceable_or_null(4), double* nonnull dereferenceable(8), i1 zeroext) + %4 = bitcast double* %1 to i32* + %5 = select i1 %2, i32* %0, i32* %4 + ret i32* %5 +} + +; TEST 3 +; GEP inbounds +define i32* @test3_1(i32* dereferenceable(8)) local_unnamed_addr { +; ATTRIBUTOR: define nonnull dereferenceable(4) i32* @test3_1(i32* nonnull dereferenceable(8)) + %ret = getelementptr inbounds i32, i32* %0, i64 1 + ret i32* %ret +} + +define i32* @test3_2(i32* dereferenceable_or_null(32)) local_unnamed_addr { +; FIXME: Argument should be mark dereferenceable because of GEP `inbounds`. +; ATTRIBUTOR: define nonnull dereferenceable(16) i32* @test3_2(i32* dereferenceable_or_null(32)) + %ret = getelementptr inbounds i32, i32* %0, i64 4 + ret i32* %ret +} + +define i32* @test3_3(i32* dereferenceable(8), i32* dereferenceable(16), i1) local_unnamed_addr { +; ATTRIBUTOR: define nonnull dereferenceable(4) i32* @test3_3(i32* nonnull dereferenceable(8), i32* nonnull dereferenceable(16), i1) local_unnamed_addr + %ret1 = getelementptr inbounds i32, i32* %0, i64 1 + %ret2 = getelementptr inbounds i32, i32* %1, i64 2 + %ret = select i1 %2, i32* %ret1, i32* %ret2 + ret i32* %ret +} + +; TEST 4 +; Better than known in IR. + +define dereferenceable(4) i32* @test4(i32* dereferenceable(8)) local_unnamed_addr { +; ATTRIBUTOR: define nonnull dereferenceable(8) i32* @test4(i32* nonnull returned dereferenceable(8)) + ret i32* %0 +} + diff --git a/llvm/test/Transforms/FunctionAttrs/noalias_returned.ll b/llvm/test/Transforms/FunctionAttrs/noalias_returned.ll index bd23ccb668b..989aa878f51 100644 --- a/llvm/test/Transforms/FunctionAttrs/noalias_returned.ll +++ b/llvm/test/Transforms/FunctionAttrs/noalias_returned.ll @@ -79,13 +79,13 @@ declare i8* @baz(...) nounwind uwtable ; TEST 5 ; Returning global pointer. Should not be noalias. -; CHECK: define nonnull i8** @getter() +; CHECK: define nonnull dereferenceable(8) i8** @getter() define i8** @getter() { ret i8** @G } ; Returning global pointer. Should not be noalias. -; CHECK: define nonnull i8** @calle1() +; CHECK: define nonnull dereferenceable(8) i8** @calle1() define i8** @calle1(){ %1 = call i8** @getter() ret i8** %1 diff --git a/llvm/test/Transforms/FunctionAttrs/nonnull.ll b/llvm/test/Transforms/FunctionAttrs/nonnull.ll index 1ea14d034c8..cab72acb1a1 100644 --- a/llvm/test/Transforms/FunctionAttrs/nonnull.ll +++ b/llvm/test/Transforms/FunctionAttrs/nonnull.ll @@ -40,14 +40,14 @@ define i8* @test3() { ; just never return period.) define i8* @test4_helper() { ; FNATTR: define noalias nonnull i8* @test4_helper -; ATTRIBUTOR: define noalias nonnull i8* @test4_helper +; ATTRIBUTOR: define noalias nonnull dereferenceable(4294967295) i8* @test4_helper %ret = call i8* @test4() ret i8* %ret } define i8* @test4() { ; FNATTR: define noalias nonnull i8* @test4 -; ATTRIBUTOR: define noalias nonnull i8* @test4 +; ATTRIBUTOR: define noalias nonnull dereferenceable(4294967295) i8* @test4 %ret = call i8* @test4_helper() ret i8* %ret } @@ -219,6 +219,15 @@ bb: %tmp = call i32* @f1(i32* %arg) ret i32* null } + +; TEST 15 +define void @f15(i8* %arg) { +; ATTRIBUTOR: tail call void @use1(i8* nonnull dereferenceable(4) %arg) + + tail call void @use1(i8* dereferenceable(4) %arg) + ret void +} + ; Test propagation of nonnull callsite args back to caller. declare void @use1(i8* %x) |