xref: /aosp_15_r20/external/llvm/test/Transforms/Reassociate/no-op.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -reassociate -S | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; When there is nothing to do, or not much to do, check that reassociate leaves
4*9880d681SAndroid Build Coastguard Worker; things alone.
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workerdeclare void @use(i32)
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Workerdefine void @test1(i32 %a, i32 %b) {
9*9880d681SAndroid Build Coastguard Worker; Shouldn't change or move any of the add instructions.  Should commute but
10*9880d681SAndroid Build Coastguard Worker; otherwise not change or move any of the mul instructions.
11*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test1(
12*9880d681SAndroid Build Coastguard Worker  %a0 = add nsw i32 %a, 1
13*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %a0 = add nsw i32 %a, 1
14*9880d681SAndroid Build Coastguard Worker  %m0 = mul nsw i32 3, %a
15*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %m0 = mul nsw i32 %a, 3
16*9880d681SAndroid Build Coastguard Worker  %a1 = add nsw i32 %a0, %b
17*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %a1 = add nsw i32 %a0, %b
18*9880d681SAndroid Build Coastguard Worker  %m1 = mul nsw i32 %b, %m0
19*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %m1 = mul nsw i32 %m0, %b
20*9880d681SAndroid Build Coastguard Worker  call void @use(i32 %a1)
21*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @use
22*9880d681SAndroid Build Coastguard Worker  call void @use(i32 %m1)
23*9880d681SAndroid Build Coastguard Worker  ret void
24*9880d681SAndroid Build Coastguard Worker}
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Workerdefine void @test2(i32 %a, i32 %b, i32 %c, i32 %d) {
27*9880d681SAndroid Build Coastguard Worker; The initial add doesn't change so should not lose the nsw flag.
28*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test2(
29*9880d681SAndroid Build Coastguard Worker  %a0 = add nsw i32 %b, %a
30*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %a0 = add nsw i32 %b, %a
31*9880d681SAndroid Build Coastguard Worker  %a1 = add nsw i32 %a0, %d
32*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %a1 = add i32 %a0, %c
33*9880d681SAndroid Build Coastguard Worker  %a2 = add nsw i32 %a1, %c
34*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %a2 = add i32 %a1, %d
35*9880d681SAndroid Build Coastguard Worker  call void @use(i32 %a2)
36*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @use
37*9880d681SAndroid Build Coastguard Worker  ret void
38*9880d681SAndroid Build Coastguard Worker}
39