File: extractelement.ll

package info (click to toggle)
intel-graphics-compiler 1.0.17791.18-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 102,312 kB
  • sloc: cpp: 935,343; lisp: 286,143; ansic: 16,196; python: 3,279; yacc: 2,487; lex: 1,642; pascal: 300; sh: 174; makefile: 27
file content (141 lines) | stat: -rw-r--r-- 4,694 bytes parent folder | download | duplicates (2)
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
;=========================== begin_copyright_notice ============================
;
; Copyright (C) 2024 Intel Corporation
;
; SPDX-License-Identifier: MIT
;
;============================ end_copyright_notice =============================
;
; RUN: igc_opt -igc-custom-safe-opt -S < %s | FileCheck %s
; ------------------------------------------------
; CustomSafeOptPass: extractelement + bitcast
; ------------------------------------------------
;
; Test checks that sequence:
; %1 = lshr i32 %0, 16,
; %2 = bitcast i32 %1 to <2 x half>
; %3 = extractelement <2 x half> %2, i32 0
; is converted to ->
; %2 = bitcast i32 %0 to <2 x half>
; %3 = extractelement <2 x half> %2, i32 1

define i16 @test_extract_lshr16(i32 %src1) {
; CHECK-LABEL: define i16 @test_extract_lshr16(
; CHECK-SAME: i32 [[SRC1:%.*]]) {
; CHECK:    [[TMP3:%.*]] = lshr i32 [[SRC1]], 16
; CHECK:    [[TMP4:%.*]] = bitcast i32 [[TMP3]] to <2 x i16>
; CHECK:    [[TMP1:%.*]] = bitcast i32 [[SRC1]] to <2 x i16>
; CHECK:    [[TMP2:%.*]] = extractelement <2 x i16> [[TMP1]], i64 1
; CHECK:    ret i16 [[TMP2]]
;
  %1 = lshr i32 %src1, 16
  %2 = bitcast i32 %1 to <2 x i16>
  %3 = extractelement <2 x i16> %2, i32 0
  ret i16 %3
}

define i16 @test_extract_lshl16(i32 %src1) {
; CHECK-LABEL: define i16 @test_extract_lshl16(
; CHECK-SAME: i32 [[SRC1:%.*]]) {
; CHECK:    [[TMP3:%.*]] = shl i32 [[SRC1]], 16
; CHECK:    [[TMP4:%.*]] = bitcast i32 [[TMP3]] to <2 x i16>
; CHECK:    [[TMP1:%.*]] = bitcast i32 [[SRC1]] to <2 x i16>
; CHECK:    [[TMP2:%.*]] = extractelement <2 x i16> [[TMP1]], i64 0
; CHECK:    ret i16 [[TMP2]]
;
  %1 = shl i32 %src1, 16
  %2 = bitcast i32 %1 to <2 x i16>
  %3 = extractelement <2 x i16> %2, i32 1
  ret i16 %3
}

define i8 @test_extract_lshr8(i32 %src1) {
; CHECK-LABEL: define i8 @test_extract_lshr8(
; CHECK-SAME: i32 [[SRC1:%.*]]) {
; CHECK:    [[TMP3:%.*]] = lshr i32 [[SRC1]], 16
; CHECK:    [[TMP4:%.*]] = bitcast i32 [[TMP3]] to <4 x i8>
; CHECK:    [[TMP1:%.*]] = bitcast i32 [[SRC1]] to <4 x i8>
; CHECK:    [[TMP2:%.*]] = extractelement <4 x i8> [[TMP1]], i64 2
; CHECK:    ret i8 [[TMP2]]
;
  %1 = lshr i32 %src1, 16
  %2 = bitcast i32 %1 to <4 x i8>
  %3 = extractelement <4 x i8> %2, i32 0
  ret i8 %3
}

define i8 @test_extract_lshl8(i32 %src1) {
; CHECK-LABEL: define i8 @test_extract_lshl8(
; CHECK-SAME: i32 [[SRC1:%.*]]) {
; CHECK:    [[TMP3:%.*]] = shl i32 [[SRC1]], 16
; CHECK:    [[TMP4:%.*]] = bitcast i32 [[TMP3]] to <4 x i8>
; CHECK:    [[TMP1:%.*]] = bitcast i32 [[SRC1]] to <4 x i8>
; CHECK:    [[TMP2:%.*]] = extractelement <4 x i8> [[TMP1]], i64 0
; CHECK:    ret i8 [[TMP2]]
;
  %1 = shl i32 %src1, 16
  %2 = bitcast i32 %1 to <4 x i8>
  %3 = extractelement <4 x i8> %2, i32 2
  ret i8 %3
}

define i1 @test_extract_lshr1(i8 %src1) {
; CHECK-LABEL: define i1 @test_extract_lshr1(
; CHECK-SAME: i8 [[SRC1:%.*]]) {
; CHECK:    [[TMP3:%.*]] = lshr i8 [[SRC1]], 1
; CHECK:    [[TMP4:%.*]] = bitcast i8 [[TMP3]] to <8 x i1>
; CHECK:    [[TMP1:%.*]] = bitcast i8 [[SRC1]] to <8 x i1>
; CHECK:    [[TMP2:%.*]] = extractelement <8 x i1> [[TMP1]], i64 7
; CHECK:    ret i1 [[TMP2]]
;
  %1 = lshr i8 %src1, 1
  %2 = bitcast i8 %1 to <8 x i1>
  %3 = extractelement <8 x i1> %2, i32 6
  ret i1 %3
}

define i1 @test_extract_lshl1(i8 %src1) {
; CHECK-LABEL: define i1 @test_extract_lshl1(
; CHECK-SAME: i8 [[SRC1:%.*]]) {
; CHECK:    [[TMP3:%.*]] = shl i8 [[SRC1]], 4
; CHECK:    [[TMP4:%.*]] = bitcast i8 [[TMP3]] to <8 x i1>
; CHECK:    [[TMP1:%.*]] = bitcast i8 [[SRC1]] to <8 x i1>
; CHECK:    [[TMP2:%.*]] = extractelement <8 x i1> [[TMP1]], i64 3
; CHECK:    ret i1 [[TMP2]]
;
  %1 = shl i8 %src1, 4
  %2 = bitcast i8 %1 to <8 x i1>
  %3 = extractelement <8 x i1> %2, i32 7
  ret i1 %3
}

; Negative cases:
; Trying to get zero parts is not optimized by this pass now
;
define i1 @test_extract_lshr_negative(i8 %src1) {
; CHECK-LABEL: define i1 @test_extract_lshr_negative(
; CHECK-SAME: i8 [[SRC1:%.*]]) {
; CHECK:    [[TMP1:%.*]] = lshr i8 [[SRC1]], 7
; CHECK:    [[TMP2:%.*]] = bitcast i8 [[TMP1]] to <8 x i1>
; CHECK:    [[TMP3:%.*]] = extractelement <8 x i1> [[TMP2]], i32 1
; CHECK:    ret i1 [[TMP3]]
;
  %1 = lshr i8 %src1, 7
  %2 = bitcast i8 %1 to <8 x i1>
  %3 = extractelement <8 x i1> %2, i32 1
  ret i1 %3
}

define i1 @test_extract_lshl_negative(i8 %src1) {
; CHECK-LABEL: define i1 @test_extract_lshl_negative(
; CHECK-SAME: i8 [[SRC1:%.*]]) {
; CHECK:    [[TMP1:%.*]] = shl i8 [[SRC1]], 4
; CHECK:    [[TMP2:%.*]] = bitcast i8 [[TMP1]] to <8 x i1>
; CHECK:    [[TMP3:%.*]] = extractelement <8 x i1> [[TMP2]], i32 3
; CHECK:    ret i1 [[TMP3]]
;
  %1 = shl i8 %src1, 4
  %2 = bitcast i8 %1 to <8 x i1>
  %3 = extractelement <8 x i1> %2, i32 3
  ret i1 %3
}