1 ; RUN: opt -passes=consthoist -S %s -o - | FileCheck %s --check-prefix=OPT
2 ; RUN: opt -passes=consthoist -S -consthoist-min-num-to-rebase=1 %s -o - | FileCheck %s --check-prefix=OPT --check-prefix=OPT-1
3 ; RUN: opt -passes=consthoist -S -consthoist-min-num-to-rebase=2 %s -o - | FileCheck %s --check-prefix=OPT --check-prefix=OPT-2
4 ; RUN: opt -passes=consthoist -S -consthoist-min-num-to-rebase=3 %s -o - | FileCheck %s --check-prefix=OPT --check-prefix=OPT-3
6 ; RUN: llc -consthoist-min-num-to-rebase=2 %s -o - | FileCheck %s --check-prefix=LLC
8 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
9 target triple = "thumbv6m-none-unknown-musleabi"
11 ; Test that constant 0 and 1 of i1 type is NOT hoisted due low
25 ; LLC-DAG: movs r{{[0-9]+}}, #0
26 ; LLC-DAG: movs r{{[0-9]+}}, #1
29 @global = local_unnamed_addr global i1 undef, align 1
30 @global.0 = local_unnamed_addr global i1 undef, align 1
32 define void @avalon() #0 {
34 switch i8 undef, label %bb5 [
41 store i1 1, ptr @global, align 1
45 store i1 0, ptr @global, align 1
49 store i1 0, ptr @global.0, align 1
50 store i1 0, ptr @global, align 1
57 ; Test that for i8 type, constant -1 is not rebased since it's the only
58 ; dependent of base constant -2.
59 ; This test is also covered by r342898, see
60 ; test/CodeGen/Thumb/consthoist-imm8-costs-1.ll
73 ; LLC-DAG: movs r{{[0-9]+}}, #254
74 ; LLC-DAG: movs r{{[0-9]+}}, #255
78 @global.1 = local_unnamed_addr global i8 undef, align 1
79 @global.2 = local_unnamed_addr global i8 undef, align 1
81 define void @barney() #0 {
83 switch i8 undef, label %bb5 [
90 store i8 -1, ptr @global.1, align 1
94 store i8 -2, ptr @global.1, align 1
98 store i8 -2, ptr @global.2, align 1
99 store i8 -2, ptr @global.1, align 1
106 ; Test that for i16 type constant 65532 is not rebased if it's the only
107 ; dependent of base constant 65531. Cost would be the same if rebased.
108 ; If rebased, 3 two-byte instructions:
112 ; If NOT rebased, 1 two-byte instruction plus 1 four-byte CP entry:
120 ; -consthoist-min-num-to-rebase=1, check that 65532 and single use of 65531
123 ; OPT-1: %[[C1:const[0-9]?]] = bitcast i16 -5 to i16
124 ; OPT-1-NEXT: %const_mat = add i16 %[[C1]], 1
125 ; OPT-1-NEXT: store i16 %const_mat, ptr @global.3, align 1
127 ; OPT-1-NEXT: %[[C2:const[0-9]?]] = bitcast i16 -5 to i16
128 ; OPT-1-NEXT: store i16 %[[C2]], ptr @global.3, align 1
130 ; OPT-1-NEXT: %[[C3:const[0-9]?]] = bitcast i16 -5 to i16
131 ; OPT-1-NEXT: store i16 %[[C3]], ptr @global.4, align 1
132 ; OPT-1-NEXT: store i16 %[[C3]], ptr @global.3, align 1
134 ; -consthoist-min-num-to-rebase=2, check that 65532 and single use of 65531
135 ; in bb2 is not rebased
137 ; OPT-2-NEXT: store i16 -4, ptr @global.3, align 1
139 ; OPT-2-NEXT: store i16 -5, ptr @global.3, align 1
141 ; OPT-2-NEXT: %[[C4:const[0-9]?]] = bitcast i16 -5 to i16
142 ; OPT-2-NEXT: store i16 %[[C4]], ptr @global.4, align 1
143 ; OPT-2-NEXT: store i16 %[[C4]], ptr @global.3, align 1
146 ; -consthoist-min-num-to-rebase=3, check that dual uses of 65531 in bb3 are
149 ; OPT-3-NEXT: store i16 -4, ptr @global.3, align 1
151 ; OPT-3-NEXT: store i16 -5, ptr @global.3, align 1
153 ; OPT-3-NEXT: store i16 -5, ptr @global.4, align 1
154 ; OPT-3-NEXT: store i16 -5, ptr @global.3, align 1
159 ; LLC-DAG: ldr r{{[0-9]+}}, .LCPI2_1
160 ; LLC-DAG: ldr r{{[0-9]+}}, .LCPI2_3
164 @global.3 = local_unnamed_addr global i16 undef, align 2
165 @global.4 = local_unnamed_addr global i16 undef, align 2
167 define void @carla() {
169 switch i8 undef, label %bb5 [
176 store i16 65532, ptr @global.3, align 1
180 store i16 65531, ptr @global.3, align 1
184 store i16 65531, ptr @global.4, align 1
185 store i16 65531, ptr @global.3, align 1