@@ -37,12 +37,6 @@ using namespace llvm;
37
37
38
38
#define DEBUG_TYPE " wasm-lower"
39
39
40
- // Emit proposed instructions that may not have been implemented in engines
41
- cl::opt<bool > EnableUnimplementedWasmSIMDInstrs (
42
- " wasm-enable-unimplemented-simd" ,
43
- cl::desc (" Emit potentially-unimplemented WebAssembly SIMD instructions" ),
44
- cl::init(false ));
45
-
46
40
WebAssemblyTargetLowering::WebAssemblyTargetLowering (
47
41
const TargetMachine &TM, const WebAssemblySubtarget &STI)
48
42
: TargetLowering(TM), Subtarget(&STI) {
@@ -70,7 +64,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
70
64
addRegisterClass (MVT::v8i16, &WebAssembly::V128RegClass);
71
65
addRegisterClass (MVT::v4i32, &WebAssembly::V128RegClass);
72
66
addRegisterClass (MVT::v4f32, &WebAssembly::V128RegClass);
73
- if (EnableUnimplementedWasmSIMDInstrs ) {
67
+ if (Subtarget-> hasSIMD128Unimplemented () ) {
74
68
addRegisterClass (MVT::v2i64, &WebAssembly::V128RegClass);
75
69
addRegisterClass (MVT::v2f64, &WebAssembly::V128RegClass);
76
70
}
@@ -135,7 +129,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
135
129
for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32}) {
136
130
setOperationAction (Op, T, Expand);
137
131
}
138
- if (EnableUnimplementedWasmSIMDInstrs ) {
132
+ if (Subtarget-> hasSIMD128Unimplemented () ) {
139
133
setOperationAction (Op, MVT::v2i64, Expand);
140
134
}
141
135
}
@@ -149,7 +143,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
149
143
for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v4f32}) {
150
144
setOperationAction (ISD::VECTOR_SHUFFLE, T, Custom);
151
145
}
152
- if (EnableUnimplementedWasmSIMDInstrs ) {
146
+ if (Subtarget-> hasSIMD128Unimplemented () ) {
153
147
setOperationAction (ISD::VECTOR_SHUFFLE, MVT::v2i64, Custom);
154
148
setOperationAction (ISD::VECTOR_SHUFFLE, MVT::v2f64, Custom);
155
149
}
@@ -160,7 +154,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
160
154
for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32})
161
155
for (auto Op : {ISD::SHL, ISD::SRA, ISD::SRL})
162
156
setOperationAction (Op, T, Custom);
163
- if (EnableUnimplementedWasmSIMDInstrs )
157
+ if (Subtarget-> hasSIMD128Unimplemented () )
164
158
for (auto Op : {ISD::SHL, ISD::SRA, ISD::SRL})
165
159
setOperationAction (Op, MVT::v2i64, Custom);
166
160
}
@@ -170,7 +164,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
170
164
for (auto Op : {ISD::VSELECT, ISD::SELECT_CC, ISD::SELECT}) {
171
165
for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v4f32})
172
166
setOperationAction (Op, T, Expand);
173
- if (EnableUnimplementedWasmSIMDInstrs )
167
+ if (Subtarget-> hasSIMD128Unimplemented () )
174
168
for (auto T : {MVT::v2i64, MVT::v2f64})
175
169
setOperationAction (Op, T, Expand);
176
170
}
@@ -179,8 +173,10 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
179
173
// sign-extend from.
180
174
setOperationAction (ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
181
175
if (!Subtarget->hasSignExt ()) {
176
+ // Sign extends are legal only when extending a vector extract
177
+ auto Action = Subtarget->hasSIMD128 () ? Custom : Expand;
182
178
for (auto T : {MVT::i8, MVT::i16, MVT::i32})
183
- setOperationAction (ISD::SIGN_EXTEND_INREG, T, Expand );
179
+ setOperationAction (ISD::SIGN_EXTEND_INREG, T, Action );
184
180
}
185
181
for (auto T : MVT::integer_vector_valuetypes ())
186
182
setOperationAction (ISD::SIGN_EXTEND_INREG, T, Expand);
@@ -225,7 +221,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
225
221
}
226
222
227
223
// Expand additional SIMD ops that V8 hasn't implemented yet
228
- if (Subtarget->hasSIMD128 () && !EnableUnimplementedWasmSIMDInstrs ) {
224
+ if (Subtarget->hasSIMD128 () && !Subtarget-> hasSIMD128Unimplemented () ) {
229
225
setOperationAction (ISD::FSQRT, MVT::v4f32, Expand);
230
226
setOperationAction (ISD::FDIV, MVT::v4f32, Expand);
231
227
}
@@ -236,7 +232,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
236
232
setOperationAction (ISD::EXTRACT_VECTOR_ELT, T, Custom);
237
233
setOperationAction (ISD::INSERT_VECTOR_ELT, T, Custom);
238
234
}
239
- if (EnableUnimplementedWasmSIMDInstrs ) {
235
+ if (Subtarget-> hasSIMD128Unimplemented () ) {
240
236
for (auto T : {MVT::v2i64, MVT::v2f64}) {
241
237
setOperationAction (ISD::EXTRACT_VECTOR_ELT, T, Custom);
242
238
setOperationAction (ISD::INSERT_VECTOR_ELT, T, Custom);
@@ -900,6 +896,8 @@ SDValue WebAssemblyTargetLowering::LowerOperation(SDValue Op,
900
896
return LowerAccessVectorElement (Op, DAG);
901
897
case ISD::INTRINSIC_VOID:
902
898
return LowerINTRINSIC_VOID (Op, DAG);
899
+ case ISD::SIGN_EXTEND_INREG:
900
+ return LowerSIGN_EXTEND_INREG (Op, DAG);
903
901
case ISD::VECTOR_SHUFFLE:
904
902
return LowerVECTOR_SHUFFLE (Op, DAG);
905
903
case ISD::SHL:
@@ -1101,6 +1099,22 @@ WebAssemblyTargetLowering::LowerINTRINSIC_VOID(SDValue Op,
1101
1099
}
1102
1100
}
1103
1101
1102
+ SDValue
1103
+ WebAssemblyTargetLowering::LowerSIGN_EXTEND_INREG (SDValue Op,
1104
+ SelectionDAG &DAG) const {
1105
+ // If sign extension operations are disabled, allow sext_inreg only if operand
1106
+ // is a vector extract. SIMD does not depend on sign extension operations, but
1107
+ // allowing sext_inreg in this context lets us have simple patterns to select
1108
+ // extract_lane_s instructions. Expanding sext_inreg everywhere would be
1109
+ // simpler in this file, but would necessitate large and brittle patterns to
1110
+ // undo the expansion and select extract_lane_s instructions.
1111
+ assert (!Subtarget->hasSignExt () && Subtarget->hasSIMD128 ());
1112
+ if (Op.getOperand (0 ).getOpcode () == ISD::EXTRACT_VECTOR_ELT)
1113
+ return Op;
1114
+ // Otherwise expand
1115
+ return SDValue ();
1116
+ }
1117
+
1104
1118
SDValue
1105
1119
WebAssemblyTargetLowering::LowerVECTOR_SHUFFLE (SDValue Op,
1106
1120
SelectionDAG &DAG) const {
0 commit comments