Skip to content

Commit 4283b2a

Browse files
committed
Rollup merge of #23692 - yjh0502:fix/simd-overflow, r=pnkfelix
Disable overflow checking on SIMD operations, fix #23037
2 parents 5a5845d + 1663665 commit 4283b2a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/librustc_trans/trans/expr.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,8 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
17661766
ast::BiAdd => {
17671767
if is_float {
17681768
FAdd(bcx, lhs, rhs, binop_debug_loc)
1769+
} else if is_simd {
1770+
Add(bcx, lhs, rhs, binop_debug_loc)
17691771
} else {
17701772
let (newbcx, res) = with_overflow_check(
17711773
bcx, OverflowOp::Add, info, lhs_t, lhs, rhs, binop_debug_loc);
@@ -1776,6 +1778,8 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
17761778
ast::BiSub => {
17771779
if is_float {
17781780
FSub(bcx, lhs, rhs, binop_debug_loc)
1781+
} else if is_simd {
1782+
Sub(bcx, lhs, rhs, binop_debug_loc)
17791783
} else {
17801784
let (newbcx, res) = with_overflow_check(
17811785
bcx, OverflowOp::Sub, info, lhs_t, lhs, rhs, binop_debug_loc);
@@ -1786,6 +1790,8 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
17861790
ast::BiMul => {
17871791
if is_float {
17881792
FMul(bcx, lhs, rhs, binop_debug_loc)
1793+
} else if is_simd {
1794+
Mul(bcx, lhs, rhs, binop_debug_loc)
17891795
} else {
17901796
let (newbcx, res) = with_overflow_check(
17911797
bcx, OverflowOp::Mul, info, lhs_t, lhs, rhs, binop_debug_loc);

src/test/run-pass/issue-23037.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(core)]
12+
13+
use std::simd::i32x4;
14+
fn main() {
15+
let foo = i32x4(1,2,3,4);
16+
let bar = i32x4(40,30,20,10);
17+
let baz = foo + bar;
18+
assert!(baz.0 == 41 && baz.1 == 32 && baz.2 == 23 && baz.3 == 14);
19+
}

0 commit comments

Comments
 (0)