diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2017-02-22 06:52:32 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2017-02-22 06:52:32 +0000 |
commit | 5cd6c5cacff5f2ec87724b7c4079b493bbbe097f (patch) | |
tree | 51a71830b959431767cb0cd35fcaaa4a866ff3d0 /llvm/test | |
parent | 64a9e3c530b0b034ff7de1277dd648ba5b95c6f6 (diff) | |
download | bcm5719-llvm-5cd6c5cacff5f2ec87724b7c4079b493bbbe097f.tar.gz bcm5719-llvm-5cd6c5cacff5f2ec87724b7c4079b493bbbe097f.zip |
[ValueTracking] Make poison propagation more aggressive
Summary:
Motivation: fix PR31181 without regression (the actual fix is still in
progress). However, the actual content of PR31181 is not relevant
here.
This change makes poison propagation more aggressive in the following
cases:
1. poision * Val == poison, for any Val. In particular, this changes
existing intentional and documented behavior in these two cases:
a. Val is 0
b. Val is 2^k * N
2. poison << Val == poison, for any Val
3. getelementptr is poison if any input is poison
I think all of these are justified (and are axiomatically true in the
new poison / undef model):
1a: we need poison * 0 to be poison to allow transforms like these:
A * (B + C) ==> A * B + A * C
If poison * 0 were 0 then the above transform could not be allowed
since e.g. we could have A = poison, B = 1, C = -1, making the LHS
poison * (1 + -1) = poison * 0 = 0
and the RHS
poison * 1 + poison * -1 = poison + poison = poison
1b: we need e.g. poison * 4 to be poison since we want to allow
A * 4 ==> A + A + A + A
If poison * 4 were a value with all of their bits poison except the
last four; then we'd not be able to do this transform since then if A
were poison the LHS would only be "partially" poison while the RHS
would be "full" poison.
2: Same reasoning as (1b), we'd like have the following kinds
transforms be legal:
A << 1 ==> A + A
Reviewers: majnemer, efriedma
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D30185
llvm-svn: 295809
Diffstat (limited to 'llvm/test')
-rw-r--r-- | llvm/test/Analysis/Delinearization/a.ll | 2 | ||||
-rw-r--r-- | llvm/test/Analysis/Delinearization/iv_times_constant_in_subscript.ll | 2 | ||||
-rw-r--r-- | llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll | 26 |
3 files changed, 13 insertions, 17 deletions
diff --git a/llvm/test/Analysis/Delinearization/a.ll b/llvm/test/Analysis/Delinearization/a.ll index 917fc355726..a105c205c5e 100644 --- a/llvm/test/Analysis/Delinearization/a.ll +++ b/llvm/test/Analysis/Delinearization/a.ll @@ -10,7 +10,7 @@ ; AddRec: {{{(28 + (4 * (-4 + (3 * %m)) * %o) + %A),+,(8 * %m * %o)}<%for.i>,+,(12 * %o)}<%for.j>,+,20}<%for.k> ; CHECK: Base offset: %A ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of 4 bytes. -; CHECK: ArrayRef[{3,+,2}<%for.i>][{-4,+,3}<%for.j>][{7,+,5}<nw><%for.k>] +; CHECK: ArrayRef[{3,+,2}<%for.i>][{-4,+,3}<nw><%for.j>][{7,+,5}<nw><%for.k>] define void @foo(i64 %n, i64 %m, i64 %o, i32* nocapture %A) #0 { entry: diff --git a/llvm/test/Analysis/Delinearization/iv_times_constant_in_subscript.ll b/llvm/test/Analysis/Delinearization/iv_times_constant_in_subscript.ll index 0c893bf1137..bd2f34df6a1 100644 --- a/llvm/test/Analysis/Delinearization/iv_times_constant_in_subscript.ll +++ b/llvm/test/Analysis/Delinearization/iv_times_constant_in_subscript.ll @@ -11,7 +11,7 @@ ; AddRec: {{((%m * %b * 8) + %A),+,(2 * %m * 8)}<%for.i>,+,(2 * 8)}<%for.j> ; CHECK: Base offset: %A ; CHECK: ArrayDecl[UnknownSize][%m] with elements of 8 bytes. -; CHECK: ArrayRef[{%b,+,2}<%for.i>][{0,+,2}<%for.j>] +; CHECK: ArrayRef[{%b,+,2}<nsw><%for.i>][{0,+,2}<%for.j>] define void @foo(i64 %n, i64 %m, i64 %b, double* %A) { diff --git a/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll b/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll index 8e73fe4fd54..44ee830d9c6 100644 --- a/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll +++ b/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll @@ -272,17 +272,16 @@ exit: ret void } -; Without inbounds, GEP does not propagate poison in the very -; conservative approach used here. -define void @test-add-no-inbounds(float* %input, i32 %offset, i32 %numIterations) { -; CHECK-LABEL: @test-add-no-inbounds +; Any poison input makes getelementptr produce poison +define void @test-gep-propagates-poison(float* %input, i32 %offset, i32 %numIterations) { +; CHECK-LABEL: @test-gep-propagates-poison entry: br label %loop loop: %i = phi i32 [ %nexti, %loop ], [ 0, %entry ] ; CHECK: %index32 = -; CHECK: --> {%offset,+,1}<nw> +; CHECK: --> {%offset,+,1}<nsw> %index32 = add nsw i32 %i, %offset %ptr = getelementptr float, float* %input, i32 %index32 @@ -317,17 +316,16 @@ exit: ret void } -; Multiplication by a non-constant should not propagate poison in the -; very conservative approach used here. -define void @test-add-mul-no-propagation(float* %input, i32 %offset, i32 %numIterations) { -; CHECK-LABEL: @test-add-mul-no-propagation +; Any poison input to multiplication propages poison. +define void @test-mul-propagates-poison(float* %input, i32 %offset, i32 %numIterations) { +; CHECK-LABEL: @test-mul-propagates-poison entry: br label %loop loop: %i = phi i32 [ %nexti, %loop ], [ 0, %entry ] ; CHECK: %index32 = -; CHECK: --> {%offset,+,1}<nw> +; CHECK: --> {%offset,+,1}<nsw> %index32 = add nsw i32 %i, %offset %indexmul = mul nsw i32 %index32, %offset @@ -340,17 +338,15 @@ exit: ret void } -; Multiplication by a non-zero constant does not propagate poison -; without a no-wrap flag. -define void @test-add-mul-no-propagation2(float* %input, i32 %offset, i32 %numIterations) { -; CHECK-LABEL: @test-add-mul-no-propagation2 +define void @test-mul-propagates-poison-2(float* %input, i32 %offset, i32 %numIterations) { +; CHECK-LABEL: @test-mul-propagates-poison-2 entry: br label %loop loop: %i = phi i32 [ %nexti, %loop ], [ 0, %entry ] ; CHECK: %index32 = -; CHECK: --> {%offset,+,1}<nw> +; CHECK: --> {%offset,+,1}<nsw> %index32 = add nsw i32 %i, %offset %indexmul = mul i32 %index32, 2 |