File: combine-sra-load.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (103 lines) | stat: -rw-r--r-- 2,931 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=CHECK

; fold (sra (load i32), 16)) -> (sextload i16)
define i32 @sra_half(i32* %p) {
; CHECK-LABEL: sra_half:
; CHECK:       # %bb.0:
; CHECK-NEXT:    movswl 2(%rdi), %eax
; CHECK-NEXT:    retq
  %load = load i32, i32* %p
  %shift = ashr i32 %load, 16
  ret i32 %shift
}

; Vector version not folded.
define <4 x i32> @sra_half_vec(<4 x i32>* %p) {
; CHECK-LABEL: sra_half_vec:
; CHECK:       # %bb.0:
; CHECK-NEXT:    movdqa (%rdi), %xmm0
; CHECK-NEXT:    psrad $16, %xmm0
; CHECK-NEXT:    retq
  %load = load <4 x i32>, <4 x i32>* %p
  %shift = ashr <4 x i32> %load, <i32 16, i32 16, i32 16, i32 16>
  ret <4 x i32> %shift
}

; fold (sra (load i64), 48)) -> (sextload i16)
define i64 @sra_large_shift(i64* %r) {
; CHECK-LABEL: sra_large_shift:
; CHECK:       # %bb.0:
; CHECK-NEXT:    movswq 6(%rdi), %rax
; CHECK-NEXT:    retq
  %t0 = load i64, i64* %r
  %conv = ashr i64 %t0, 48
  ret i64 %conv
}

; Negative test, no fold expected.
define i32 @sra_small_shift(i32* %p) {
; CHECK-LABEL: sra_small_shift:
; CHECK:       # %bb.0:
; CHECK-NEXT:    movl (%rdi), %eax
; CHECK-NEXT:    sarl $8, %eax
; CHECK-NEXT:    retq
  %load = load i32, i32* %p
  %shift = ashr i32 %load, 8
  ret i32 %shift
}

; This should be folded to a zextload.
define i32 @sra_of_zextload(i16* %p) {
; CHECK-LABEL: sra_of_zextload:
; CHECK:       # %bb.0:
; CHECK-NEXT:    movzbl 1(%rdi), %eax
; CHECK-NEXT:    retq
  %load = load i16, i16* %p
  %zext = zext i16 %load to i32
  %shift = ashr i32 %zext, 8
  ret i32 %shift
}

; fold (sra (sextload i16 to i32), 8) -> (sextload i8)
define i32 @sra_of_sextload(i16* %p) {
; CHECK-LABEL: sra_of_sextload:
; CHECK:       # %bb.0:
; CHECK-NEXT:    movsbl 1(%rdi), %eax
; CHECK-NEXT:    retq
  %load = load i16, i16* %p
  %sext = sext i16 %load to i32
  %shift = ashr i32 %sext, 8
  ret i32 %shift
}

; Negative test. If the shift amount is larger than the memory type then
; we're not accessing any of the loaded bytes (only the extended bits). So the
; shift is expected to remain.
define i32 @sra_of_sextload_no_fold(i16* %p) {
; CHECK-LABEL: sra_of_sextload_no_fold:
; CHECK:       # %bb.0:
; CHECK-NEXT:    movswl (%rdi), %eax
; CHECK-NEXT:    sarl $16, %eax
; CHECK-NEXT:    retq
  %load = load i16, i16* %p
  %sext = sext i16 %load to i32
  %shift = ashr i32 %sext, 16
  ret i32 %shift
}

; Fold even if SRA has multiple uses.
define i32 @sra_to_sextload_multiple_sra_uses(i32* %p) {
; CHECK-LABEL: sra_to_sextload_multiple_sra_uses:
; CHECK:       # %bb.0:
; CHECK-NEXT:    movswl 2(%rdi), %ecx
; CHECK-NEXT:    movl %ecx, %eax
; CHECK-NEXT:    xorl $6, %eax
; CHECK-NEXT:    orl %ecx, %eax
; CHECK-NEXT:    retq
  %load = load i32, i32* %p
  %shift = ashr i32 %load, 16
  %use1 = xor i32 %shift, 6
  %use2 = or i32 %shift, %use1
  ret i32 %use2
}