Skip to content

Commit 6b305f3

Browse files
committed
auto merge of #11907 : sanxiyn/rust/simd-shift, r=thestinger
For the purpose of deciding whether to truncate or extend the right hand side of bit shifts, use the size of the element type for SIMD vector types. Fix #11900.
2 parents e3b1f3c + 5f68142 commit 6b305f3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/librustc/middle/trans/base.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use driver::session;
3030
use driver::session::Session;
3131
use driver::driver::{CrateAnalysis, CrateTranslation};
3232
use lib::llvm::{ModuleRef, ValueRef, BasicBlockRef};
33-
use lib::llvm::{llvm, True};
33+
use lib::llvm::{llvm, True, Vector};
3434
use lib;
3535
use metadata::common::LinkMeta;
3636
use metadata::{csearch, encoder};
@@ -827,8 +827,10 @@ pub fn cast_shift_rhs(op: ast::BinOp,
827827
// Shifts may have any size int on the rhs
828828
unsafe {
829829
if ast_util::is_shift_binop(op) {
830-
let rhs_llty = val_ty(rhs);
831-
let lhs_llty = val_ty(lhs);
830+
let mut rhs_llty = val_ty(rhs);
831+
let mut lhs_llty = val_ty(lhs);
832+
if rhs_llty.kind() == Vector { rhs_llty = rhs_llty.element_type() }
833+
if lhs_llty.kind() == Vector { lhs_llty = lhs_llty.element_type() }
832834
let rhs_sz = llvm::LLVMGetIntTypeWidth(rhs_llty.to_ref());
833835
let lhs_sz = llvm::LLVMGetIntTypeWidth(lhs_llty.to_ref());
834836
if lhs_sz < rhs_sz {

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#[allow(experimental)];
1212

13-
use std::unstable::simd::{i32x4, f32x4};
13+
use std::unstable::simd::{i32x4, f32x4, u32x4};
1414

1515
fn test_int(e: i32) -> i32 {
1616
let v = i32x4(e, 0i32, 0i32, 0i32);
@@ -24,7 +24,15 @@ fn test_float(e: f32) -> f32 {
2424
e2
2525
}
2626

27+
pub fn test_shift(e: u32) -> u32 {
28+
let v = u32x4(e, 0u32, 0u32, 0u32);
29+
let one = u32x4(1u32, 0u32, 0u32, 0u32);
30+
let u32x4(e2, _, _, _) = v << one >> one;
31+
e2
32+
}
33+
2734
pub fn main() {
2835
assert_eq!(test_int(3i32), 9i32);
2936
assert_eq!(test_float(3f32), 9f32);
37+
assert_eq!(test_shift(3u32), 3u32);
3038
}

0 commit comments

Comments
 (0)