Skip to content

Commit d10601a

Browse files
committed
Rollup merge of #23704 - hirschenberger:simd-intdiv-ice, r=huonw
Fixes #23339
2 parents e7c61a4 + 62645a1 commit d10601a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/librustc_trans/trans/base.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use middle::cfg;
4141
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
4242
use middle::weak_lang_items;
4343
use middle::subst::{Subst, Substs};
44-
use middle::ty::{self, Ty, ClosureTyper};
44+
use middle::ty::{self, Ty, ClosureTyper, type_is_simd, simd_size};
4545
use session::config::{self, NoDebugInfo};
4646
use session::Session;
4747
use trans::_match;
@@ -52,7 +52,7 @@ use trans::callee;
5252
use trans::cleanup::CleanupMethods;
5353
use trans::cleanup;
5454
use trans::closure;
55-
use trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral};
55+
use trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_int, C_integral};
5656
use trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_undef};
5757
use trans::common::{CrateContext, ExternMap, FunctionContext};
5858
use trans::common::{Result, NodeIdAndSpan};
@@ -824,6 +824,15 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
824824
let zero = C_integral(Type::uint_from_ty(cx.ccx(), t), 0, false);
825825
(ICmp(cx, llvm::IntEQ, rhs, zero, debug_loc), false)
826826
}
827+
ty::ty_struct(_, _) if type_is_simd(cx.tcx(), rhs_t) => {
828+
let mut res = C_bool(cx.ccx(), false);
829+
for i in 0 .. simd_size(cx.tcx(), rhs_t) {
830+
res = Or(cx, res,
831+
IsNull(cx,
832+
ExtractElement(cx, rhs, C_int(cx.ccx(), i as i64))), debug_loc);
833+
}
834+
(res, false)
835+
}
827836
_ => {
828837
cx.sess().bug(&format!("fail-if-zero on unexpected type: {}",
829838
ty_to_string(cx.tcx(), rhs_t)));

src/test/run-pass/simd-binop.rs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn main() {
3232
assert!(eq_u32x4(u32x4(1, 2, 3, 4) + u32x4(4, 3, 2, 1), u32x4(5, 5, 5, 5)));
3333
assert!(eq_u32x4(u32x4(4, 5, 6, 7) - u32x4(4, 3, 2, 1), u32x4(0, 2, 4, 6)));
3434
assert!(eq_u32x4(u32x4(1, 2, 3, 4) * u32x4(4, 3, 2, 1), u32x4(4, 6, 6, 4)));
35+
assert!(eq_u32x4(u32x4(1, 2, 3, 4) / u32x4(4, 3, 2, 1), u32x4(0, 0, 1, 4)));
3536
assert!(eq_u32x4(u32x4(1, 2, 3, 4) & u32x4(4, 3, 2, 1), u32x4(0, 2, 2, 0)));
3637
assert!(eq_u32x4(u32x4(1, 2, 3, 4) | u32x4(4, 3, 2, 1), u32x4(5, 3, 3, 5)));
3738
assert!(eq_u32x4(u32x4(1, 2, 3, 4) ^ u32x4(4, 3, 2, 1), u32x4(5, 1, 1, 5)));
@@ -41,6 +42,7 @@ pub fn main() {
4142
assert!(eq_i32x4(i32x4(1, 2, 3, 4) + i32x4(4, 3, 2, 1), i32x4(5, 5, 5, 5)));
4243
assert!(eq_i32x4(i32x4(1, 2, 3, 4) - i32x4(4, 3, 2, 1), i32x4(-3, -1, 1, 3)));
4344
assert!(eq_i32x4(i32x4(1, 2, 3, 4) * i32x4(4, 3, 2, 1), i32x4(4, 6, 6, 4)));
45+
assert!(eq_i32x4(i32x4(1, 2, 3, 4) / i32x4(4, 3, 2, 1), i32x4(0, 0, 1, 4)));
4446
assert!(eq_i32x4(i32x4(1, 2, 3, 4) & i32x4(4, 3, 2, 1), i32x4(0, 2, 2, 0)));
4547
assert!(eq_i32x4(i32x4(1, 2, 3, 4) | i32x4(4, 3, 2, 1), i32x4(5, 3, 3, 5)));
4648
assert!(eq_i32x4(i32x4(1, 2, 3, 4) ^ i32x4(4, 3, 2, 1), i32x4(5, 1, 1, 5)));

0 commit comments

Comments
 (0)