@@ -1183,25 +1183,45 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg
1183
1183
case or_int: return ctx.builder .CreateOr (x, y);
1184
1184
case xor_int: return ctx.builder .CreateXor (x, y);
1185
1185
1186
- case shl_int:
1187
- return ctx.builder .CreateSelect (
1188
- ctx.builder .CreateICmpUGE (y, ConstantInt::get (y->getType (),
1189
- t->getPrimitiveSizeInBits ())),
1190
- ConstantInt::get (t, 0 ),
1191
- ctx.builder .CreateShl (x, uint_cnvt (ctx, t, y)));
1192
- case lshr_int:
1193
- return ctx.builder .CreateSelect (
1194
- ctx.builder .CreateICmpUGE (y, ConstantInt::get (y->getType (),
1195
- t->getPrimitiveSizeInBits ())),
1196
- ConstantInt::get (t, 0 ),
1197
- ctx.builder .CreateLShr (x, uint_cnvt (ctx, t, y)));
1198
- case ashr_int:
1199
- return ctx.builder .CreateSelect (
1200
- ctx.builder .CreateICmpUGE (y, ConstantInt::get (y->getType (),
1201
- t->getPrimitiveSizeInBits ())),
1202
- ctx.builder .CreateAShr (x, ConstantInt::get (t, t->getPrimitiveSizeInBits () - 1 )),
1203
- ctx.builder .CreateAShr (x, uint_cnvt (ctx, t, y)));
1204
-
1186
+ case shl_int: {
1187
+ Value *the_shl = ctx.builder .CreateShl (x, uint_cnvt (ctx, t, y));
1188
+ if (ConstantInt::isValueValidForType (y->getType (), t->getPrimitiveSizeInBits ())) {
1189
+ return ctx.builder .CreateSelect (
1190
+ ctx.builder .CreateICmpUGE (y, ConstantInt::get (y->getType (),
1191
+ t->getPrimitiveSizeInBits ())),
1192
+ ConstantInt::get (t, 0 ),
1193
+ the_shl);
1194
+ }
1195
+ else {
1196
+ return the_shl;
1197
+ }
1198
+ }
1199
+ case lshr_int: {
1200
+ Value *the_shr = ctx.builder .CreateLShr (x, uint_cnvt (ctx, t, y));
1201
+ if (ConstantInt::isValueValidForType (y->getType (), t->getPrimitiveSizeInBits ())) {
1202
+ return ctx.builder .CreateSelect (
1203
+ ctx.builder .CreateICmpUGE (y, ConstantInt::get (y->getType (),
1204
+ t->getPrimitiveSizeInBits ())),
1205
+ ConstantInt::get (t, 0 ),
1206
+ the_shr);
1207
+ }
1208
+ else {
1209
+ return the_shr;
1210
+ }
1211
+ }
1212
+ case ashr_int: {
1213
+ Value *the_shr = ctx.builder .CreateAShr (x, uint_cnvt (ctx, t, y));
1214
+ if (ConstantInt::isValueValidForType (y->getType (), t->getPrimitiveSizeInBits ())) {
1215
+ return ctx.builder .CreateSelect (
1216
+ ctx.builder .CreateICmpUGE (y, ConstantInt::get (y->getType (),
1217
+ t->getPrimitiveSizeInBits ())),
1218
+ ctx.builder .CreateAShr (x, ConstantInt::get (t, t->getPrimitiveSizeInBits () - 1 )),
1219
+ the_shr);
1220
+ }
1221
+ else {
1222
+ return the_shr;
1223
+ }
1224
+ }
1205
1225
case bswap_int: {
1206
1226
FunctionCallee bswapintr = Intrinsic::getDeclaration (jl_Module, Intrinsic::bswap, makeArrayRef (t));
1207
1227
return ctx.builder .CreateCall (bswapintr, x);
0 commit comments