1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64I
7 ; Test for handling of AND with constant followed by a shift by constant. Often
8 ; we can replace these with a pair of shifts to avoid materializing a constant
11 define i32 @test1(i32 %x) {
14 ; RV32I-NEXT: srli a0, a0, 5
15 ; RV32I-NEXT: andi a0, a0, -8
20 ; RV64I-NEXT: srliw a0, a0, 8
21 ; RV64I-NEXT: slli a0, a0, 3
24 %b = and i32 %a, 134217720
28 define i64 @test2(i64 %x) {
31 ; RV32I-NEXT: slli a2, a1, 27
32 ; RV32I-NEXT: srli a0, a0, 5
33 ; RV32I-NEXT: or a0, a0, a2
34 ; RV32I-NEXT: srli a1, a1, 5
35 ; RV32I-NEXT: andi a0, a0, -8
40 ; RV64I-NEXT: srli a0, a0, 5
41 ; RV64I-NEXT: andi a0, a0, -8
44 %b = and i64 %a, 576460752303423480
48 define i32 @test3(i32 %x) {
51 ; RV32I-NEXT: srli a0, a0, 20
52 ; RV32I-NEXT: slli a0, a0, 14
57 ; RV64I-NEXT: srliw a0, a0, 20
58 ; RV64I-NEXT: slli a0, a0, 14
61 %b = and i32 %a, 67092480
65 define i64 @test4(i64 %x) {
68 ; RV32I-NEXT: slli a2, a1, 26
69 ; RV32I-NEXT: srli a0, a0, 6
70 ; RV32I-NEXT: or a0, a0, a2
71 ; RV32I-NEXT: srli a1, a1, 6
72 ; RV32I-NEXT: lui a2, 1048572
73 ; RV32I-NEXT: and a0, a0, a2
78 ; RV64I-NEXT: srli a0, a0, 20
79 ; RV64I-NEXT: slli a0, a0, 14
82 %b = and i64 %a, 288230376151695360
86 define i32 @test5(i32 %x) {
89 ; RV32I-NEXT: srli a0, a0, 10
90 ; RV32I-NEXT: slli a0, a0, 16
95 ; RV64I-NEXT: andi a0, a0, -1024
96 ; RV64I-NEXT: slliw a0, a0, 6
99 %b = and i32 %a, -65536
103 define i64 @test6(i64 %x) {
104 ; RV32I-LABEL: test6:
106 ; RV32I-NEXT: srli a2, a0, 26
107 ; RV32I-NEXT: slli a1, a1, 6
108 ; RV32I-NEXT: or a1, a1, a2
109 ; RV32I-NEXT: srli a0, a0, 10
110 ; RV32I-NEXT: slli a0, a0, 16
113 ; RV64I-LABEL: test6:
115 ; RV64I-NEXT: srli a0, a0, 10
116 ; RV64I-NEXT: slli a0, a0, 16
119 %b = and i64 %a, -65536