1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=CHECK
4 ; fold (sra (load i32), 16)) -> (sextload i16)
5 define i32 @sra_half(ptr %p) {
6 ; CHECK-LABEL: sra_half:
8 ; CHECK-NEXT: movswl 2(%rdi), %eax
10 %load = load i32, ptr %p
11 %shift = ashr i32 %load, 16
15 ; Vector version not folded.
16 define <4 x i32> @sra_half_vec(ptr %p) {
17 ; CHECK-LABEL: sra_half_vec:
19 ; CHECK-NEXT: movdqa (%rdi), %xmm0
20 ; CHECK-NEXT: psrad $16, %xmm0
22 %load = load <4 x i32>, ptr %p
23 %shift = ashr <4 x i32> %load, <i32 16, i32 16, i32 16, i32 16>
27 ; fold (sra (load i64), 48)) -> (sextload i16)
28 define i64 @sra_large_shift(ptr %r) {
29 ; CHECK-LABEL: sra_large_shift:
31 ; CHECK-NEXT: movswq 6(%rdi), %rax
33 %t0 = load i64, ptr %r
34 %conv = ashr i64 %t0, 48
38 ; Negative test, no fold expected.
39 define i32 @sra_small_shift(ptr %p) {
40 ; CHECK-LABEL: sra_small_shift:
42 ; CHECK-NEXT: movl (%rdi), %eax
43 ; CHECK-NEXT: sarl $8, %eax
45 %load = load i32, ptr %p
46 %shift = ashr i32 %load, 8
50 ; This should be folded to a zextload.
51 define i32 @sra_of_zextload(ptr %p) {
52 ; CHECK-LABEL: sra_of_zextload:
54 ; CHECK-NEXT: movzbl 1(%rdi), %eax
56 %load = load i16, ptr %p
57 %zext = zext i16 %load to i32
58 %shift = ashr i32 %zext, 8
62 ; fold (sra (sextload i16 to i32), 8) -> (sextload i8)
63 define i32 @sra_of_sextload(ptr %p) {
64 ; CHECK-LABEL: sra_of_sextload:
66 ; CHECK-NEXT: movsbl 1(%rdi), %eax
68 %load = load i16, ptr %p
69 %sext = sext i16 %load to i32
70 %shift = ashr i32 %sext, 8
74 ; Negative test. If the shift amount is larger than the memory type then
75 ; we're not accessing any of the loaded bytes (only the extended bits). So the
76 ; shift is expected to remain.
77 define i32 @sra_of_sextload_no_fold(ptr %p) {
78 ; CHECK-LABEL: sra_of_sextload_no_fold:
80 ; CHECK-NEXT: movswl (%rdi), %eax
81 ; CHECK-NEXT: sarl $16, %eax
83 %load = load i16, ptr %p
84 %sext = sext i16 %load to i32
85 %shift = ashr i32 %sext, 16
89 ; Fold even if SRA has multiple uses.
90 define i32 @sra_to_sextload_multiple_sra_uses(ptr %p) {
91 ; CHECK-LABEL: sra_to_sextload_multiple_sra_uses:
93 ; CHECK-NEXT: movswl 2(%rdi), %ecx
94 ; CHECK-NEXT: movl %ecx, %eax
95 ; CHECK-NEXT: xorl $6, %eax
96 ; CHECK-NEXT: imull %ecx, %eax
98 %load = load i32, ptr %p
99 %shift = ashr i32 %load, 16
100 %use1 = xor i32 %shift, 6
101 %use2 = mul i32 %shift, %use1