1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -p iroutliner,verify -ir-outlining-no-cost < %s | FileCheck %s
4 ; This test checks that commutative instructions where the operands are
5 ; swapped are outlined as the same function.
7 ; It also checks that non-commutative instructions outlined as different
8 ; functions when the operands are swapped;
10 ; These are identical functions, except that in the flipped functions,
11 ; the operands in the adds are commuted. However, since add instructions
12 ; are commutative, we should still outline from all four as the same
15 define void @function1(i32 %a, i32 %b) {
16 ; CHECK-LABEL: @function1(
18 ; CHECK-NEXT: br label [[BLOCK_1:%.*]]
20 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
21 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[TMP4:%.*]], 1
22 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP0]], [[TMP0]]
23 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i32 [[TMP0]], [[TMP0]]
24 ; CHECK-NEXT: br i1 [[TMP3]], label [[BLOCK_1]], label [[BLOCK_2:%.*]]
26 ; CHECK-NEXT: [[TMP4]] = phi i32 [ [[TMP1]], [[BLOCK_0:%.*]] ], [ 0, [[ENTRY:%.*]] ]
27 ; CHECK-NEXT: call void @outlined_ir_func_0(i32 [[B]])
28 ; CHECK-NEXT: br label [[BLOCK_0]]
30 ; CHECK-NEXT: [[TMP5:%.*]] = add i32 [[TMP2]], [[TMP2]]
31 ; CHECK-NEXT: ret void
40 %3 = icmp sgt i32 %0, %0
41 br i1 %3, label %block_1, label %block_2
44 %4 = phi i32 [ %1, %block_0 ], [ 0, %entry ]
53 define void @function2(i32 %a, i32 %b) {
54 ; CHECK-LABEL: @function2(
56 ; CHECK-NEXT: br label [[BLOCK_1:%.*]]
58 ; CHECK-NEXT: [[TMP0:%.*]] = sub i32 [[A:%.*]], [[B:%.*]]
59 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 1, [[TMP4:%.*]]
60 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP0]], [[TMP0]]
61 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i32 [[TMP0]], [[TMP0]]
62 ; CHECK-NEXT: br i1 [[TMP3]], label [[BLOCK_1]], label [[BLOCK_2:%.*]]
64 ; CHECK-NEXT: [[TMP4]] = phi i32 [ [[TMP1]], [[BLOCK_0:%.*]] ], [ 0, [[ENTRY:%.*]] ]
65 ; CHECK-NEXT: call void @outlined_ir_func_0(i32 [[B]])
66 ; CHECK-NEXT: br label [[BLOCK_0]]
68 ; CHECK-NEXT: [[TMP5:%.*]] = sub i32 [[TMP2]], [[TMP2]]
69 ; CHECK-NEXT: ret void
78 %3 = icmp sgt i32 %0, %0
79 br i1 %3, label %block_1, label %block_2
82 %4 = phi i32 [ %1, %block_0 ], [ 0, %entry ]