1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32I %s
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV64I %s
7 ; These test that constant adds are not moved after shifts by DAGCombine,
8 ; if the constant is cheaper to materialise before it has been shifted.
10 define signext i32 @add_small_const(i32 signext %a) nounwind {
11 ; RV32I-LABEL: add_small_const:
13 ; RV32I-NEXT: addi a0, a0, 1
14 ; RV32I-NEXT: slli a0, a0, 24
15 ; RV32I-NEXT: srai a0, a0, 24
18 ; RV64I-LABEL: add_small_const:
20 ; RV64I-NEXT: addi a0, a0, 1
21 ; RV64I-NEXT: slli a0, a0, 56
22 ; RV64I-NEXT: srai a0, a0, 56
30 define signext i32 @add_large_const(i32 signext %a) nounwind {
31 ; RV32I-LABEL: add_large_const:
33 ; RV32I-NEXT: slli a0, a0, 16
34 ; RV32I-NEXT: lui a1, 65520
35 ; RV32I-NEXT: add a0, a0, a1
36 ; RV32I-NEXT: srai a0, a0, 16
39 ; RV64I-LABEL: add_large_const:
41 ; RV64I-NEXT: lui a1, 1
42 ; RV64I-NEXT: addiw a1, a1, -1
43 ; RV64I-NEXT: add a0, a0, a1
44 ; RV64I-NEXT: slli a0, a0, 48
45 ; RV64I-NEXT: srai a0, a0, 48
53 define signext i32 @add_huge_const(i32 signext %a) nounwind {
54 ; RV32I-LABEL: add_huge_const:
56 ; RV32I-NEXT: slli a0, a0, 16
57 ; RV32I-NEXT: lui a1, 524272
58 ; RV32I-NEXT: add a0, a0, a1
59 ; RV32I-NEXT: srai a0, a0, 16
62 ; RV64I-LABEL: add_huge_const:
64 ; RV64I-NEXT: lui a1, 8
65 ; RV64I-NEXT: addiw a1, a1, -1
66 ; RV64I-NEXT: add a0, a0, a1
67 ; RV64I-NEXT: slli a0, a0, 48
68 ; RV64I-NEXT: srai a0, a0, 48
70 %1 = add i32 %a, 32767
76 define signext i24 @add_non_machine_type(i24 signext %a) nounwind {
77 ; RV32I-LABEL: add_non_machine_type:
79 ; RV32I-NEXT: addi a0, a0, 256
80 ; RV32I-NEXT: slli a0, a0, 20
81 ; RV32I-NEXT: srai a0, a0, 8
84 ; RV64I-LABEL: add_non_machine_type:
86 ; RV64I-NEXT: addi a0, a0, 256
87 ; RV64I-NEXT: slli a0, a0, 52
88 ; RV64I-NEXT: srai a0, a0, 40