File: xor-ashr.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 (153 lines) | stat: -rw-r--r-- 5,014 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"

declare void @use16(i16)
declare void @use32(i32)

define i8 @testi8i8(i8 %add) {
; CHECK-LABEL: @testi8i8(
; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i8 [[ADD:%.*]], -1
; CHECK-NEXT:    [[X:%.*]] = select i1 [[TMP1]], i8 127, i8 -128
; CHECK-NEXT:    ret i8 [[X]]
;
  %sh = ashr i8 %add, 7
  %x = xor i8 %sh, 127
  ret i8 %x
}

define i8 @testi16i8(i16 %add) {
; CHECK-LABEL: @testi16i8(
; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i16 [[ADD:%.*]], -1
; CHECK-NEXT:    [[X:%.*]] = select i1 [[TMP1]], i8 27, i8 -28
; CHECK-NEXT:    ret i8 [[X]]
;
  %sh = ashr i16 %add, 15
  %t = trunc i16 %sh to i8
  %x = xor i8 %t, 27
  ret i8 %x
}

define i32 @testi64i32(i64 %add) {
; CHECK-LABEL: @testi64i32(
; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i64 [[ADD:%.*]], -1
; CHECK-NEXT:    [[X:%.*]] = select i1 [[TMP1]], i32 127, i32 -128
; CHECK-NEXT:    ret i32 [[X]]
;
  %sh = ashr i64 %add, 63
  %t = trunc i64 %sh to i32
  %x = xor i32 %t, 127
  ret i32 %x
}

define i128 @testi128i128(i128 %add) {
; CHECK-LABEL: @testi128i128(
; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i128 [[ADD:%.*]], -1
; CHECK-NEXT:    [[X:%.*]] = select i1 [[TMP1]], i128 27, i128 -28
; CHECK-NEXT:    ret i128 [[X]]
;
  %sh = ashr i128 %add, 127
  %x = xor i128 %sh, 27
  ret i128 %x
}

define <4 x i8> @testv4i16i8(<4 x i16> %add) {
; CHECK-LABEL: @testv4i16i8(
; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt <4 x i16> [[ADD:%.*]], <i16 -1, i16 -1, i16 -1, i16 -1>
; CHECK-NEXT:    [[X:%.*]] = select <4 x i1> [[TMP1]], <4 x i8> <i8 27, i8 27, i8 27, i8 27>, <4 x i8> <i8 -28, i8 -28, i8 -28, i8 -28>
; CHECK-NEXT:    ret <4 x i8> [[X]]
;
  %sh = ashr <4 x i16> %add, <i16 15, i16 15, i16 15, i16 15>
  %t = trunc <4 x i16> %sh to <4 x i8>
  %x = xor <4 x i8> %t, <i8 27, i8 27, i8 27, i8 27>
  ret <4 x i8> %x
}

define <4 x i8> @testv4i16i8_undef(<4 x i16> %add) {
; CHECK-LABEL: @testv4i16i8_undef(
; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt <4 x i16> [[ADD:%.*]], <i16 -1, i16 -1, i16 -1, i16 -1>
; CHECK-NEXT:    [[X:%.*]] = select <4 x i1> [[TMP1]], <4 x i8> <i8 27, i8 27, i8 undef, i8 27>, <4 x i8> <i8 -28, i8 -28, i8 undef, i8 -28>
; CHECK-NEXT:    ret <4 x i8> [[X]]
;
  %sh = ashr <4 x i16> %add, <i16 15, i16 undef, i16 15, i16 15>
  %t = trunc <4 x i16> %sh to <4 x i8>
  %x = xor <4 x i8> %t, <i8 27, i8 27, i8 undef, i8 27>
  ret <4 x i8> %x
}

; Negative tests

define i8 @wrongimm(i16 %add) {
; CHECK-LABEL: @wrongimm(
; CHECK-NEXT:    [[SH:%.*]] = ashr i16 [[ADD:%.*]], 14
; CHECK-NEXT:    [[T:%.*]] = trunc i16 [[SH]] to i8
; CHECK-NEXT:    [[X:%.*]] = xor i8 [[T]], 27
; CHECK-NEXT:    ret i8 [[X]]
;
  %sh = ashr i16 %add, 14
  %t = trunc i16 %sh to i8
  %x = xor i8 %t, 27
  ret i8 %x
}

; PR52397 Some of the lanes of the xor/ashr are unused, becoming poison.
define <4 x i32> @vectorpoison(<6 x i32> %0) {
; CHECK-LABEL: @vectorpoison(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[NEG:%.*]] = ashr <6 x i32> [[TMP0:%.*]], <i32 31, i32 31, i32 31, i32 31, i32 31, i32 31>
; CHECK-NEXT:    [[SHR:%.*]] = xor <6 x i32> [[NEG]], <i32 -1, i32 -1, i32 -1, i32 poison, i32 poison, i32 poison>
; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <6 x i32> [[SHR]], <6 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 2>
; CHECK-NEXT:    ret <4 x i32> [[TMP1]]
;
entry:
  %neg = xor <6 x i32> %0, <i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1>
  %shr = ashr <6 x i32> %neg, <i32 31, i32 31, i32 31, i32 31, i32 31, i32 31>
  %1 = shufflevector <6 x i32> %shr, <6 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 2>
  ret <4 x i32> %1
}


; One use

define i16 @extrause(i16 %add) {
; CHECK-LABEL: @extrause(
; CHECK-NEXT:    [[SH:%.*]] = ashr i16 [[ADD:%.*]], 15
; CHECK-NEXT:    [[X:%.*]] = xor i16 [[SH]], 27
; CHECK-NEXT:    call void @use16(i16 [[SH]])
; CHECK-NEXT:    ret i16 [[X]]
;
  %sh = ashr i16 %add, 15
  %x = xor i16 %sh, 27
  call void @use16(i16 %sh)
  ret i16 %x
}

define i16 @extrause_trunc1(i32 %add) {
; CHECK-LABEL: @extrause_trunc1(
; CHECK-NEXT:    [[SH:%.*]] = ashr i32 [[ADD:%.*]], 31
; CHECK-NEXT:    call void @use32(i32 [[SH]])
; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i32 [[ADD]], -1
; CHECK-NEXT:    [[X:%.*]] = select i1 [[TMP1]], i16 127, i16 -128
; CHECK-NEXT:    ret i16 [[X]]
;
  %sh = ashr i32 %add, 31
  %t = trunc i32 %sh to i16
  call void @use32(i32 %sh)
  %x = xor i16 %t, 127
  ret i16 %x
}

define i16 @extrause_trunc2(i32 %add) {
; CHECK-LABEL: @extrause_trunc2(
; CHECK-NEXT:    [[SH:%.*]] = ashr i32 [[ADD:%.*]], 31
; CHECK-NEXT:    [[T:%.*]] = trunc i32 [[SH]] to i16
; CHECK-NEXT:    call void @use16(i16 [[T]])
; CHECK-NEXT:    [[X:%.*]] = xor i16 [[T]], 127
; CHECK-NEXT:    ret i16 [[X]]
;
  %sh = ashr i32 %add, 31
  %t = trunc i32 %sh to i16
  call void @use16(i16 %t)
  %x = xor i16 %t, 127
  ret i16 %x
}