xref: /llvm-project/llvm/test/Transforms/IROutliner/outlining-constants-vs-registers.ll (revision f4b925ee7078f058602fd323e25f45f1ae91ca34)
1c52bcf3aSAndrew Litteken; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
29dd9575cSRoman Lebedev; RUN: opt -S -passes=verify,iroutliner -ir-outlining-no-cost < %s | FileCheck %s
3c52bcf3aSAndrew Litteken
4c52bcf3aSAndrew Litteken; This test looks at instances of constants in the different regions. If there
5c52bcf3aSAndrew Litteken; is a register in the same place as a constant in a similar region of code, we
6c52bcf3aSAndrew Litteken; do not outline those regions.
7c52bcf3aSAndrew Litteken
8c52bcf3aSAndrew Litteken; The first function tests that we do not outline with the register is
9c52bcf3aSAndrew Litteken; seen first, and the second function checks that we do not outline when the
10c52bcf3aSAndrew Litteken; constant is seen first.
11c52bcf3aSAndrew Litteken
12c52bcf3aSAndrew Littekendefine void @function_registers_first(i32 %0, i32 %1, i32 %2) {
13c52bcf3aSAndrew Litteken; CHECK-LABEL: @function_registers_first(
14c52bcf3aSAndrew Litteken; CHECK-NEXT:  entry:
15c52bcf3aSAndrew Litteken; CHECK-NEXT:    [[A:%.*]] = alloca i32, align 4
16c52bcf3aSAndrew Litteken; CHECK-NEXT:    [[B:%.*]] = alloca i32, align 4
17c52bcf3aSAndrew Litteken; CHECK-NEXT:    [[C:%.*]] = alloca i32, align 4
18*f4b925eeSMatt Arsenault; CHECK-NEXT:    call void @outlined_ir_func_1(i32 [[TMP0:%.*]], ptr [[A]], i32 [[TMP1:%.*]], ptr [[B]], i32 [[TMP2:%.*]], ptr [[C]])
19c52bcf3aSAndrew Litteken; CHECK-NEXT:    ret void
20c52bcf3aSAndrew Litteken; CHECK:       next:
21*f4b925eeSMatt Arsenault; CHECK-NEXT:    call void @outlined_ir_func_1(i32 2, ptr [[A]], i32 3, ptr [[B]], i32 4, ptr [[C]])
22c52bcf3aSAndrew Litteken; CHECK-NEXT:    ret void
23c52bcf3aSAndrew Litteken;
24c52bcf3aSAndrew Littekenentry:
25c52bcf3aSAndrew Litteken  %a = alloca i32, align 4
26c52bcf3aSAndrew Litteken  %b = alloca i32, align 4
27c52bcf3aSAndrew Litteken  %c = alloca i32, align 4
28*f4b925eeSMatt Arsenault  store i32 %0, ptr %a, align 4
29*f4b925eeSMatt Arsenault  store i32 %1, ptr %b, align 4
30*f4b925eeSMatt Arsenault  store i32 %2, ptr %c, align 4
31c52bcf3aSAndrew Litteken  ret void
32c52bcf3aSAndrew Littekennext:
33*f4b925eeSMatt Arsenault  store i32 2, ptr %a, align 4
34*f4b925eeSMatt Arsenault  store i32 3, ptr %b, align 4
35*f4b925eeSMatt Arsenault  store i32 4, ptr %c, align 4
36c52bcf3aSAndrew Litteken  ret void
37c52bcf3aSAndrew Litteken}
38c52bcf3aSAndrew Litteken
39b1191c84SAndrew Littekendefine void @function_with_constants_first(i32 %0, i32 %1, i32 %2) {
40c52bcf3aSAndrew Litteken; CHECK-LABEL: @function_with_constants_first(
41c52bcf3aSAndrew Litteken; CHECK-NEXT:  entry:
42c52bcf3aSAndrew Litteken; CHECK-NEXT:    [[A:%.*]] = alloca i32, align 4
43c52bcf3aSAndrew Litteken; CHECK-NEXT:    [[B:%.*]] = alloca i32, align 4
44c52bcf3aSAndrew Litteken; CHECK-NEXT:    [[C:%.*]] = alloca i32, align 4
45*f4b925eeSMatt Arsenault; CHECK-NEXT:    [[AL:%.*]] = load i32, ptr [[A]], align 4
46*f4b925eeSMatt Arsenault; CHECK-NEXT:    [[BL:%.*]] = load i32, ptr [[B]], align 4
47*f4b925eeSMatt Arsenault; CHECK-NEXT:    [[CL:%.*]] = load i32, ptr [[C]], align 4
48b1191c84SAndrew Litteken; CHECK-NEXT:    call void @outlined_ir_func_0(i32 2, i32 [[AL]], i32 3, i32 [[BL]], i32 4, i32 [[CL]])
49c52bcf3aSAndrew Litteken; CHECK-NEXT:    ret void
50c52bcf3aSAndrew Litteken; CHECK:       next:
51b1191c84SAndrew Litteken; CHECK-NEXT:    call void @outlined_ir_func_0(i32 [[TMP0:%.*]], i32 [[AL]], i32 [[TMP1:%.*]], i32 [[BL]], i32 [[TMP2:%.*]], i32 [[CL]])
52c52bcf3aSAndrew Litteken; CHECK-NEXT:    ret void
53c52bcf3aSAndrew Litteken;
54c52bcf3aSAndrew Littekenentry:
55c52bcf3aSAndrew Litteken  %a = alloca i32, align 4
56c52bcf3aSAndrew Litteken  %b = alloca i32, align 4
57c52bcf3aSAndrew Litteken  %c = alloca i32, align 4
58*f4b925eeSMatt Arsenault  %al = load i32, ptr %a
59*f4b925eeSMatt Arsenault  %bl = load i32, ptr %b
60*f4b925eeSMatt Arsenault  %cl = load i32, ptr %c
61b1191c84SAndrew Litteken  %3 = add i32 2, %al
62b1191c84SAndrew Litteken  %4 = add i32 3, %bl
63b1191c84SAndrew Litteken  %5 = add i32 4, %cl
64c52bcf3aSAndrew Litteken  ret void
65c52bcf3aSAndrew Littekennext:
66b1191c84SAndrew Litteken  %6 = add i32 %0, %al
67b1191c84SAndrew Litteken  %7 = add i32 %1, %bl
68b1191c84SAndrew Litteken  %8 = add i32 %2, %cl
69c52bcf3aSAndrew Litteken  ret void
70c52bcf3aSAndrew Litteken}
71b1191c84SAndrew Litteken
72b1191c84SAndrew Litteken; CHECK: define internal void @outlined_ir_func_0(i32 [[ARG0:%.*]], i32 [[ARG1:%.*]], i32 [[ARG2:%.*]], i32 [[ARG3:%.*]], i32 [[ARG4:%.*]], i32 [[ARG5:%.*]])
73b1191c84SAndrew Litteken; CHECK: entry_to_outline:
74b1191c84SAndrew Litteken; CHECK-NEXT: add i32 [[ARG0]], [[ARG1]]
75b1191c84SAndrew Litteken; CHECK-NEXT: add i32 [[ARG2]], [[ARG3]]
76b1191c84SAndrew Litteken; CHECK-NEXT: add i32 [[ARG4]], [[ARG5]]
77b1191c84SAndrew Litteken
78*f4b925eeSMatt Arsenault; CHECK: define internal void @outlined_ir_func_1(i32 [[ARG0:%.*]], ptr [[ARG1:%.*]], i32 [[ARG2:%.*]], ptr [[ARG3:%.*]], i32 [[ARG4:%.*]], ptr [[ARG5:%.*]])
79b1191c84SAndrew Litteken; CHECK: entry_to_outline:
80*f4b925eeSMatt Arsenault; CHECK-NEXT: store i32 [[ARG0]], ptr [[ARG1]]
81*f4b925eeSMatt Arsenault; CHECK-NEXT: store i32 [[ARG2]], ptr [[ARG3]]
82*f4b925eeSMatt Arsenault; CHECK-NEXT: store i32 [[ARG4]], ptr [[ARG5]]
83