diff options
| author | Chad Rosier <mcrosier@codeaurora.org> | 2017-08-23 14:10:06 +0000 |
|---|---|---|
| committer | Chad Rosier <mcrosier@codeaurora.org> | 2017-08-23 14:10:06 +0000 |
| commit | 8db41e9dbd141d9904da6e29d098a49eed933400 (patch) | |
| tree | ab8907a7f9ce70ede359fc4485038a43fab1b6cd /llvm/test/Transforms | |
| parent | 06ed529205634a55e246a8123673de3ce4b79139 (diff) | |
| download | bcm5719-llvm-8db41e9dbd141d9904da6e29d098a49eed933400.tar.gz bcm5719-llvm-8db41e9dbd141d9904da6e29d098a49eed933400.zip | |
[Reassociate] Don't canonicalize x + (-Constant * y) -> x - (Constant * y)..
..if the resulting subtract will be broken up later. This can cause us to get
into an infinite loop.
x + (-5.0 * y) -> x - (5.0 * y) ; Canonicalize neg const
x - (5.0 * y) -> x + (0 - (5.0 * y)) ; Break up subtract
x + (0 - (5.0 * y)) -> x + (-5.0 * y) ; Replace 0-X with X*-1.
PR34078
llvm-svn: 311554
Diffstat (limited to 'llvm/test/Transforms')
| -rw-r--r-- | llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll b/llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll index 465460cb53b..7cb2c3a10e2 100644 --- a/llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll +++ b/llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll @@ -154,3 +154,25 @@ define i4 @test13(i4 %x) { %add = add i4 %mul, 3 ret i4 %add } + +; This tests used to cause an infinite loop where we would loop between +; canonicalizing the negated constant (i.e., (X + Y*-5.0) -> (X - Y*5.0)) and +; breaking up a subtract (i.e., (X - Y*5.0) -> X + (0 - Y*5.0)). To break the +; cycle, we don't canonicalize the negative constant if we're going to later +; break up the subtract. +; +; Check to make sure we don't canonicalize +; (%pow2*-5.0 + %sub) -> (%sub - %pow2*5.0) +; as we would later break up this subtract causing a cycle. +; +; CHECK-LABEL: @pr34078 +; CHECK: %mul5.neg = fmul fast double %pow2, -5.000000e-01 +; CHECK: %sub1 = fadd fast double %mul5.neg, %sub +define double @pr34078(double %A) { + %sub = fsub fast double 1.000000e+00, %A + %pow2 = fmul double %A, %A + %mul5 = fmul fast double %pow2, 5.000000e-01 + %sub1 = fsub fast double %sub, %mul5 + %add = fadd fast double %sub1, %sub1 + ret double %add +} |

