Skip to content

Commit bcc68c2

Browse files
committed
Rustup to rustc 1.54.0-nightly (881c1ac 2021-05-08)
1 parent 961d8b6 commit bcc68c2

File tree

4 files changed

+101
-26
lines changed

4 files changed

+101
-26
lines changed

example/std_example.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,6 @@ unsafe fn test_mm_slli_si128() {
187187
);
188188
let r = _mm_slli_si128(a, 16);
189189
assert_eq_m128i(r, _mm_set1_epi8(0));
190-
191-
#[rustfmt::skip]
192-
let a = _mm_setr_epi8(
193-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
194-
);
195-
let r = _mm_slli_si128(a, -1);
196-
assert_eq_m128i(_mm_set1_epi8(0), r);
197-
198-
#[rustfmt::skip]
199-
let a = _mm_setr_epi8(
200-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
201-
);
202-
let r = _mm_slli_si128(a, -0x80000000);
203-
assert_eq_m128i(r, _mm_set1_epi8(0));
204190
}
205191

206192
#[cfg(target_arch = "x86_64")]
@@ -295,7 +281,7 @@ unsafe fn test_mm_extract_epi8() {
295281
8, 9, 10, 11, 12, 13, 14, 15
296282
);
297283
let r1 = _mm_extract_epi8(a, 0);
298-
let r2 = _mm_extract_epi8(a, 19);
284+
let r2 = _mm_extract_epi8(a, 3);
299285
assert_eq!(r1, 0xFF);
300286
assert_eq!(r2, 3);
301287
}

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-05-04"
2+
channel = "nightly-2021-05-09"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

src/constant.rs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,89 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
448448
operand: &Operand<'tcx>,
449449
) -> Option<ConstValue<'tcx>> {
450450
match operand {
451-
Operand::Copy(_) | Operand::Move(_) => None,
452451
Operand::Constant(const_) => match const_.literal {
453452
ConstantKind::Ty(const_) => {
454453
fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val.try_to_value()
455454
}
456455
ConstantKind::Val(val, _) => Some(val),
457456
},
457+
// FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
458+
// inside a temporary before being passed to the intrinsic requiring the const argument.
459+
// This code tries to find a single constant defining definition of the referenced local.
460+
Operand::Copy(place) | Operand::Move(place) => {
461+
if !place.projection.is_empty() {
462+
return None;
463+
}
464+
let mut computed_const_val = None;
465+
for bb_data in fx.mir.basic_blocks() {
466+
for stmt in &bb_data.statements {
467+
match &stmt.kind {
468+
StatementKind::Assign(local_and_rvalue) if &local_and_rvalue.0 == place => {
469+
match &local_and_rvalue.1 {
470+
Rvalue::Cast(CastKind::Misc, operand, ty) => {
471+
if computed_const_val.is_some() {
472+
return None; // local assigned twice
473+
}
474+
if !matches!(ty.kind(), ty::Uint(_) | ty::Int(_)) {
475+
return None;
476+
}
477+
let const_val = mir_operand_get_const_val(fx, operand)?;
478+
if fx.layout_of(ty).size
479+
!= const_val.try_to_scalar_int()?.size()
480+
{
481+
return None;
482+
}
483+
computed_const_val = Some(const_val);
484+
}
485+
Rvalue::Use(operand) => {
486+
computed_const_val = mir_operand_get_const_val(fx, operand)
487+
}
488+
_ => return None,
489+
}
490+
}
491+
StatementKind::SetDiscriminant { place: stmt_place, variant_index: _ }
492+
if &**stmt_place == place =>
493+
{
494+
return None;
495+
}
496+
StatementKind::LlvmInlineAsm(_) | StatementKind::CopyNonOverlapping(_) => {
497+
return None;
498+
} // conservative handling
499+
StatementKind::Assign(_)
500+
| StatementKind::FakeRead(_)
501+
| StatementKind::SetDiscriminant { .. }
502+
| StatementKind::StorageLive(_)
503+
| StatementKind::StorageDead(_)
504+
| StatementKind::Retag(_, _)
505+
| StatementKind::AscribeUserType(_, _)
506+
| StatementKind::Coverage(_)
507+
| StatementKind::Nop => {}
508+
}
509+
}
510+
match &bb_data.terminator().kind {
511+
TerminatorKind::Goto { .. }
512+
| TerminatorKind::SwitchInt { .. }
513+
| TerminatorKind::Resume
514+
| TerminatorKind::Abort
515+
| TerminatorKind::Return
516+
| TerminatorKind::Unreachable
517+
| TerminatorKind::Drop { .. }
518+
| TerminatorKind::Assert { .. } => {}
519+
TerminatorKind::DropAndReplace { .. }
520+
| TerminatorKind::Yield { .. }
521+
| TerminatorKind::GeneratorDrop
522+
| TerminatorKind::FalseEdge { .. }
523+
| TerminatorKind::FalseUnwind { .. } => unreachable!(),
524+
TerminatorKind::InlineAsm { .. } => return None,
525+
TerminatorKind::Call { destination: Some((call_place, _)), .. }
526+
if call_place == place =>
527+
{
528+
return None;
529+
}
530+
TerminatorKind::Call { .. } => {}
531+
}
532+
}
533+
computed_const_val
534+
}
458535
}
459536
}

src/inline_asm.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,22 @@ pub(crate) fn codegen_inline_asm<'tcx>(
2424
let true_ = fx.bcx.ins().iconst(types::I32, 1);
2525
fx.bcx.ins().trapnz(true_, TrapCode::User(1));
2626
return;
27-
} else if template[0] == InlineAsmTemplatePiece::String("mov rsi, rbx".to_string())
28-
&& template[1] == InlineAsmTemplatePiece::String("\n".to_string())
29-
&& template[2] == InlineAsmTemplatePiece::String("cpuid".to_string())
30-
&& template[3] == InlineAsmTemplatePiece::String("\n".to_string())
31-
&& template[4] == InlineAsmTemplatePiece::String("xchg rsi, rbx".to_string())
27+
} else if template[0] == InlineAsmTemplatePiece::String("movq %rbx, ".to_string())
28+
&& matches!(
29+
template[1],
30+
InlineAsmTemplatePiece::Placeholder { operand_idx: 0, modifier: Some('r'), span: _ }
31+
)
32+
&& template[2] == InlineAsmTemplatePiece::String("\n".to_string())
33+
&& template[3] == InlineAsmTemplatePiece::String("cpuid".to_string())
34+
&& template[4] == InlineAsmTemplatePiece::String("\n".to_string())
35+
&& template[5] == InlineAsmTemplatePiece::String("xchgq %rbx, ".to_string())
36+
&& matches!(
37+
template[6],
38+
InlineAsmTemplatePiece::Placeholder { operand_idx: 0, modifier: Some('r'), span: _ }
39+
)
3240
{
3341
assert_eq!(operands.len(), 4);
34-
let (leaf, eax_place) = match operands[0] {
42+
let (leaf, eax_place) = match operands[1] {
3543
InlineAsmOperand::InOut { reg, late: true, ref in_value, out_place } => {
3644
let reg = expect_reg(reg);
3745
assert_eq!(reg, InlineAsmReg::X86(X86InlineAsmReg::ax));
@@ -42,10 +50,14 @@ pub(crate) fn codegen_inline_asm<'tcx>(
4250
}
4351
_ => unreachable!(),
4452
};
45-
let ebx_place = match operands[1] {
53+
let ebx_place = match operands[0] {
4654
InlineAsmOperand::Out { reg, late: true, place } => {
47-
let reg = expect_reg(reg);
48-
assert_eq!(reg, InlineAsmReg::X86(X86InlineAsmReg::si));
55+
assert_eq!(
56+
reg,
57+
InlineAsmRegOrRegClass::RegClass(InlineAsmRegClass::X86(
58+
X86InlineAsmRegClass::reg
59+
))
60+
);
4961
crate::base::codegen_place(fx, place.unwrap())
5062
}
5163
_ => unreachable!(),

0 commit comments

Comments
 (0)