Skip to content

Commit 47c008e

Browse files
committed
Auto merge of #103098 - Amanieu:asm-tied-fixed, r=bjorn3
asm: Match clang behavior for inlateout fixed register operands We have 2 options for representing LLVM constraints for `inlateout` operands on a fixed register (e.g. `r0`): `={r0},0` or `={r0},{r0}`. This PR changes the behavior to the latter, which matches the behavior of Clang since https://reviews.llvm.org/D87279.
2 parents 2efb0cd + 6bfe7f0 commit 47c008e

File tree

1 file changed

+11
-2
lines changed
  • compiler/rustc_codegen_llvm/src

1 file changed

+11
-2
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,24 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
130130
op_idx.insert(idx, constraints.len());
131131
constraints.push(reg_to_llvm(reg, Some(&value.layout)));
132132
}
133-
InlineAsmOperandRef::InOut { reg, late: _, in_value, out_place: _ } => {
133+
InlineAsmOperandRef::InOut { reg, late, in_value, out_place: _ } => {
134134
let value = llvm_fixup_input(
135135
self,
136136
in_value.immediate(),
137137
reg.reg_class(),
138138
&in_value.layout,
139139
);
140140
inputs.push(value);
141-
constraints.push(format!("{}", op_idx[&idx]));
141+
142+
// In the case of fixed registers, we have the choice of
143+
// either using a tied operand or duplicating the constraint.
144+
// We prefer the latter because it matches the behavior of
145+
// Clang.
146+
if late && matches!(reg, InlineAsmRegOrRegClass::Reg(_)) {
147+
constraints.push(format!("{}", reg_to_llvm(reg, Some(&in_value.layout))));
148+
} else {
149+
constraints.push(format!("{}", op_idx[&idx]));
150+
}
142151
}
143152
InlineAsmOperandRef::SymFn { instance } => {
144153
inputs.push(self.cx.get_fn(instance));

0 commit comments

Comments
 (0)