blob: 7b02df99464b85f0f57ac75a4d54adfbc54866a3 [file] [log] [blame]
Duncan Sands3c05cd32012-05-26 16:42:52 +00001; RUN: opt < %s -reassociate -S | FileCheck %s
2
3; When there is nothing to do, or not much to do, check that reassociate leaves
4; things alone.
5
6declare void @use(i32)
7
8define void @test1(i32 %a, i32 %b) {
9; Shouldn't change or move any of the add instructions. Should commute but
10; otherwise not change or move any of the mul instructions.
Stephen Linc1c7a132013-07-14 01:42:54 +000011; CHECK-LABEL: @test1(
Duncan Sands3c05cd32012-05-26 16:42:52 +000012 %a0 = add nsw i32 %a, 1
13; CHECK-NEXT: %a0 = add nsw i32 %a, 1
14 %m0 = mul nsw i32 3, %a
15; CHECK-NEXT: %m0 = mul nsw i32 %a, 3
16 %a1 = add nsw i32 %a0, %b
17; CHECK-NEXT: %a1 = add nsw i32 %a0, %b
18 %m1 = mul nsw i32 %b, %m0
19; CHECK-NEXT: %m1 = mul nsw i32 %m0, %b
20 call void @use(i32 %a1)
21; CHECK-NEXT: call void @use
22 call void @use(i32 %m1)
23 ret void
24}
25
26define void @test2(i32 %a, i32 %b, i32 %c, i32 %d) {
27; The initial add doesn't change so should not lose the nsw flag.
Stephen Linc1c7a132013-07-14 01:42:54 +000028; CHECK-LABEL: @test2(
Duncan Sands3c05cd32012-05-26 16:42:52 +000029 %a0 = add nsw i32 %b, %a
Chad Rosier90a2f9b2014-11-19 23:21:20 +000030; CHECK-NEXT: %a0 = add nsw i32 %b, %a
Duncan Sands3c05cd32012-05-26 16:42:52 +000031 %a1 = add nsw i32 %a0, %d
32; CHECK-NEXT: %a1 = add i32 %a0, %c
33 %a2 = add nsw i32 %a1, %c
Chad Rosier90a2f9b2014-11-19 23:21:20 +000034; CHECK-NEXT: %a2 = add i32 %a1, %d
Duncan Sands3c05cd32012-05-26 16:42:52 +000035 call void @use(i32 %a2)
36; CHECK-NEXT: call void @use
37 ret void
38}