1 ; RUN: opt -mtriple=riscv32-unknown-elf -S -passes=consthoist < %s | FileCheck %s
2 ; RUN: opt -mtriple=riscv64-unknown-elf -S -passes=consthoist < %s | FileCheck %s
4 ; Check that we don't hoist immediates with small values.
5 define i64 @test1(i64 %a) nounwind {
7 ; CHECK-NOT: %const = bitcast i64 2 to i64
13 ; Check that we don't hoist immediates with small values.
14 define i64 @test2(i64 %a) nounwind {
16 ; CHECK-NOT: %const = bitcast i64 2047 to i64
22 ; Check that we hoist immediates with large values.
23 define i64 @test3(i64 %a) nounwind {
25 ; CHECK: %const = bitcast i64 32766 to i64
26 %1 = mul i64 %a, 32766
27 %2 = add i64 %1, 32766
31 ; Check that we hoist immediates with very large values.
32 define i128 @test4(i128 %a) nounwind {
34 ; CHECK: %const = bitcast i128 12297829382473034410122878 to i128
35 %1 = add i128 %a, 12297829382473034410122878
36 %2 = add i128 %1, 12297829382473034410122878
40 ; Check that we hoist zext.h without Zbb.
41 define i32 @test5(i32 %a) nounwind {
43 ; CHECK: %const = bitcast i32 65535 to i32
44 %1 = and i32 %a, 65535
45 %2 = and i32 %1, 65535
49 ; Check that we don't hoist zext.h with 65535 with Zbb.
50 define i32 @test6(i32 %a) nounwind "target-features"="+zbb" {
52 ; CHECK: and i32 %a, 65535
53 %1 = and i32 %a, 65535
54 %2 = and i32 %1, 65535
58 ; Check that we hoist zext.w without Zba.
59 define i64 @test7(i64 %a) nounwind {
61 ; CHECK: %const = bitcast i64 4294967295 to i64
62 %1 = and i64 %a, 4294967295
63 %2 = and i64 %1, 4294967295
67 ; Check that we don't hoist zext.w with Zba.
68 define i64 @test8(i64 %a) nounwind "target-features"="+zba" {
70 ; CHECK: and i64 %a, 4294967295
71 %1 = and i64 %a, 4294967295
72 %2 = and i64 %1, 4294967295
76 ; Check that we don't hoist mul with negated power of 2.
77 define i64 @test9(i64 %a) nounwind {
79 ; CHECK: mul i64 %a, -4294967296
80 %1 = mul i64 %a, -4294967296
81 %2 = mul i64 %1, -4294967296
85 define i32 @test10(i32 %a, i32 %b) nounwind {
86 ; CHECK-LABEL: @test10(
87 ; CHECK: shl i32 %a, 8
88 ; CHECK: and i32 %1, 65280
89 ; CHECK: shl i32 %b, 8
90 ; CHECK: and i32 %3, 65280
92 %2 = and i32 %1, 65280
94 %4 = and i32 %3, 65280
100 define i64 @test11(i64 %a) nounwind "target-features"="+zbs" {
101 ; CHECK-LABEL: test11
102 ; CHECK: or i64 %a, 8589934592
103 %1 = or i64 %a, 8589934592 ; 1 << 33
104 %2 = or i64 %1, 8589934592 ; 1 << 33
109 define i64 @test12(i64 %a) nounwind "target-features"="+zbs" {
110 ; CHECK-LABEL: test12
111 ; CHECK: xor i64 %a, -9223372036854775808
112 %1 = xor i64 %a, -9223372036854775808 ; 1 << 63
113 %2 = xor i64 %1, -9223372036854775808 ; 1 << 63
118 define i64 @test13(i64 %a) nounwind "target-features"="+zbs" {
119 ; CHECK-LABEL: test13
120 ; CHECK: and i64 %a, -281474976710657
121 %1 = and i64 %a, -281474976710657 ; ~(1 << 48)
122 %2 = and i64 %1, -281474976710657 ; ~(1 << 48)
126 ; Check that we don't hoist mul by a power of 2.
127 define i64 @test14(i64 %a) nounwind {
128 ; CHECK-LABEL: test14
129 ; CHECK: mul i64 %a, 2048
130 %1 = mul i64 %a, 2048
131 %2 = mul i64 %1, 2048
135 ; Check that we don't hoist mul by one less than a power of 2.
136 define i64 @test15(i64 %a) nounwind {
137 ; CHECK-LABEL: test15
138 ; CHECK: mul i64 %a, 65535
139 %1 = mul i64 %a, 65535
140 %2 = mul i64 %1, 65535
144 ; Check that we don't hoist mul by one more than a power of 2.
145 define i64 @test16(i64 %a) nounwind {
146 ; CHECK-LABEL: test16
147 ; CHECK: mul i64 %a, 65537
148 %1 = mul i64 %a, 65537
149 %2 = mul i64 %1, 65537