1; 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.
11; CHECK-LABEL: @test1(
12  %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.
28; CHECK-LABEL: @test2(
29  %a0 = add nsw i32 %b, %a
30; CHECK-NEXT: %a0 = add nsw i32 %b, %a
31  %a1 = add nsw i32 %a0, %d
32; CHECK-NEXT: %a1 = add i32 %a0, %c
33  %a2 = add nsw i32 %a1, %c
34; CHECK-NEXT: %a2 = add i32 %a1, %d
35  call void @use(i32 %a2)
36; CHECK-NEXT: call void @use
37  ret void
38}
39