blob: 6b2041898a1d3f0ab61813b12c44657d34eaaa52 [file] [log] [blame]
Tanya Lattner028031a2008-03-19 04:36:04 +00001; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis | not grep sub
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002
3; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z.
4
Tanya Lattner028031a2008-03-19 04:36:04 +00005define i32 @test1(i32 %a, i32 %b, i32 %z) {
6 %c = sub i32 0, %z ; <i32> [#uses=1]
7 %d = mul i32 %a, %b ; <i32> [#uses=1]
8 %e = mul i32 %c, %d ; <i32> [#uses=1]
9 %f = mul i32 %e, 12345 ; <i32> [#uses=1]
10 %g = sub i32 0, %f ; <i32> [#uses=1]
11 ret i32 %g
Dan Gohmanf17a25c2007-07-18 16:29:46 +000012}
13
Tanya Lattner028031a2008-03-19 04:36:04 +000014define i32 @test2(i32 %a, i32 %b, i32 %z) {
15 %d = mul i32 %z, 40 ; <i32> [#uses=1]
16 %c = sub i32 0, %d ; <i32> [#uses=1]
17 %e = mul i32 %a, %c ; <i32> [#uses=1]
18 %f = sub i32 0, %e ; <i32> [#uses=1]
19 ret i32 %f
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020}
Tanya Lattner028031a2008-03-19 04:36:04 +000021