Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3590f4c

Browse files
committed
Work around more LLVM limitations
1 parent 19a0d14 commit 3590f4c

File tree

1 file changed

+76
-1
lines changed
  • src/librustc_codegen_llvm

1 file changed

+76
-1
lines changed

src/librustc_codegen_llvm/asm.rs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass) -> String {
409409
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => "f",
410410
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg) => "r",
411411
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd) => "Q",
412-
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_byte) => "r",
412+
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_byte) => "q",
413413
InlineAsmRegClass::X86(X86InlineAsmRegClass::xmm_reg)
414414
| InlineAsmRegClass::X86(X86InlineAsmRegClass::ymm_reg) => "x",
415415
InlineAsmRegClass::X86(X86InlineAsmRegClass::zmm_reg) => "v",
@@ -558,6 +558,31 @@ fn llvm_fixup_input(
558558
let indices: Vec<_> = (0..count * 2).map(|x| bx.const_i32(x as i32)).collect();
559559
bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices))
560560
}
561+
(InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s))
562+
if s.value == Primitive::F64 =>
563+
{
564+
bx.bitcast(value, bx.cx.type_i64())
565+
}
566+
(
567+
InlineAsmRegClass::X86(X86InlineAsmRegClass::xmm_reg | X86InlineAsmRegClass::zmm_reg),
568+
Abi::Vector { .. },
569+
) if layout.size.bytes() == 64 => bx.bitcast(value, bx.cx.type_vector(bx.cx.type_f64(), 8)),
570+
(
571+
InlineAsmRegClass::Arm(
572+
ArmInlineAsmRegClass::sreg_low16
573+
| ArmInlineAsmRegClass::dreg_low8
574+
| ArmInlineAsmRegClass::qreg_low4
575+
| ArmInlineAsmRegClass::dreg
576+
| ArmInlineAsmRegClass::qreg,
577+
),
578+
Abi::Scalar(s),
579+
) => {
580+
if let Primitive::Int(Integer::I32, _) = s.value {
581+
bx.bitcast(value, bx.cx.type_f32())
582+
} else {
583+
value
584+
}
585+
}
561586
_ => value,
562587
}
563588
}
@@ -593,6 +618,31 @@ fn llvm_fixup_output(
593618
let indices: Vec<_> = (0..*count).map(|x| bx.const_i32(x as i32)).collect();
594619
bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices))
595620
}
621+
(InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s))
622+
if s.value == Primitive::F64 =>
623+
{
624+
bx.bitcast(value, bx.cx.type_f64())
625+
}
626+
(
627+
InlineAsmRegClass::X86(X86InlineAsmRegClass::xmm_reg | X86InlineAsmRegClass::zmm_reg),
628+
Abi::Vector { .. },
629+
) if layout.size.bytes() == 64 => bx.bitcast(value, layout.llvm_type(bx.cx)),
630+
(
631+
InlineAsmRegClass::Arm(
632+
ArmInlineAsmRegClass::sreg_low16
633+
| ArmInlineAsmRegClass::dreg_low8
634+
| ArmInlineAsmRegClass::qreg_low4
635+
| ArmInlineAsmRegClass::dreg
636+
| ArmInlineAsmRegClass::qreg,
637+
),
638+
Abi::Scalar(s),
639+
) => {
640+
if let Primitive::Int(Integer::I32, _) = s.value {
641+
bx.bitcast(value, bx.cx.type_i32())
642+
} else {
643+
value
644+
}
645+
}
596646
_ => value,
597647
}
598648
}
@@ -623,6 +673,31 @@ fn llvm_fixup_output_type(
623673
let elem_ty = llvm_asm_scalar_type(cx, element);
624674
cx.type_vector(elem_ty, count * 2)
625675
}
676+
(InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s))
677+
if s.value == Primitive::F64 =>
678+
{
679+
cx.type_i64()
680+
}
681+
(
682+
InlineAsmRegClass::X86(X86InlineAsmRegClass::xmm_reg | X86InlineAsmRegClass::zmm_reg),
683+
Abi::Vector { .. },
684+
) if layout.size.bytes() == 64 => cx.type_vector(cx.type_f64(), 8),
685+
(
686+
InlineAsmRegClass::Arm(
687+
ArmInlineAsmRegClass::sreg_low16
688+
| ArmInlineAsmRegClass::dreg_low8
689+
| ArmInlineAsmRegClass::qreg_low4
690+
| ArmInlineAsmRegClass::dreg
691+
| ArmInlineAsmRegClass::qreg,
692+
),
693+
Abi::Scalar(s),
694+
) => {
695+
if let Primitive::Int(Integer::I32, _) = s.value {
696+
cx.type_f32()
697+
} else {
698+
layout.llvm_type(cx)
699+
}
700+
}
626701
_ => layout.llvm_type(cx),
627702
}
628703
}

0 commit comments

Comments
 (0)