Skip to content

Commit f0d403a

Browse files
committed
Update is_clobbered_in_inst to affect only clobbers, not all defs.
1 parent ee5cced commit f0d403a

File tree

16 files changed

+69
-107
lines changed

16 files changed

+69
-107
lines changed

cranelift/codegen/src/isa/aarch64/abi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,6 @@ impl ABIMachineSpec for AArch64MachineDeps {
10941094
caller_conv: call_conv,
10951095
callee_conv: call_conv,
10961096
callee_pop_size: 0,
1097-
has_non_abi_defs: false,
10981097
}),
10991098
});
11001099
insts

cranelift/codegen/src/isa/aarch64/inst/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,6 @@ impl MachInst for Inst {
979979
fn is_included_in_clobbers(&self) -> bool {
980980
let (caller, callee) = match self {
981981
Inst::Args { .. } => return false,
982-
Inst::Call { info } if info.has_non_abi_defs => return true,
983-
Inst::CallInd { info } if info.has_non_abi_defs => return true,
984982
Inst::Call { info } => (info.caller_conv, info.callee_conv),
985983
Inst::CallInd { info } => (info.caller_conv, info.callee_conv),
986984
_ => return true,

cranelift/codegen/src/isa/riscv64/abi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ impl ABIMachineSpec for Riscv64MachineDeps {
614614
caller_conv: call_conv,
615615
callee_conv: call_conv,
616616
callee_pop_size: 0,
617-
has_non_abi_defs: false,
618617
}),
619618
});
620619
insts

cranelift/codegen/src/isa/s390x/inst/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,9 +1069,7 @@ impl MachInst for Inst {
10691069
// registers.
10701070
match self {
10711071
&Inst::Args { .. } => false,
1072-
&Inst::Call { ref info, .. } => {
1073-
info.caller_conv != info.callee_conv || info.has_non_abi_defs
1074-
}
1072+
&Inst::Call { ref info, .. } => info.caller_conv != info.callee_conv,
10751073
&Inst::CallInd { ref info, .. } => info.caller_conv != info.callee_conv,
10761074
&Inst::ElfTlsGetOffset { .. } => false,
10771075
_ => true,

cranelift/codegen/src/isa/s390x/lower/isle.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@ impl IsleContext<'_, '_, MInst, S390xBackend> {
999999
callee_pop_size,
10001000
caller_conv: self.lower_ctx.abi().call_conv(self.lower_ctx.sigs()),
10011001
callee_conv: self.lower_ctx.sigs()[abi].call_conv(),
1002-
has_non_abi_defs: false,
10031002
}
10041003
}
10051004
}

cranelift/codegen/src/isa/x64/abi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,6 @@ impl ABIMachineSpec for X64ABIMachineSpec {
877877
defs: smallvec![],
878878
clobbers: Self::get_regs_clobbered_by_call(call_conv),
879879
callee_pop_size,
880-
has_non_abi_defs: false,
881880
callee_conv: call_conv,
882881
caller_conv: call_conv,
883882
})));

cranelift/codegen/src/machinst/abi.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,6 @@ pub struct CallInfo<T> {
620620
/// caller, if any. (Used for popping stack arguments with the `tail`
621621
/// calling convention.)
622622
pub callee_pop_size: u32,
623-
/// Do the defs have any definitions outside of the ABI-implied
624-
/// clobbers? If so, this instruction needs to be considered when
625-
/// computing the function body's clobbered registers.
626-
pub has_non_abi_defs: bool,
627623
}
628624

629625
impl<T> CallInfo<T> {
@@ -638,7 +634,6 @@ impl<T> CallInfo<T> {
638634
caller_conv: call_conv,
639635
callee_conv: call_conv,
640636
callee_pop_size: 0,
641-
has_non_abi_defs: false,
642637
}
643638
}
644639

@@ -652,7 +647,6 @@ impl<T> CallInfo<T> {
652647
caller_conv: self.caller_conv,
653648
callee_conv: self.callee_conv,
654649
callee_pop_size: self.callee_pop_size,
655-
has_non_abi_defs: self.has_non_abi_defs,
656650
}
657651
}
658652
}
@@ -2036,9 +2030,6 @@ pub struct CallSite<M: ABIMachineSpec> {
20362030
caller_conv: isa::CallConv,
20372031
/// The settings controlling this compilation.
20382032
flags: settings::Flags,
2039-
/// Has any defs that are not constrained to ABI-specified
2040-
/// registers.
2041-
has_non_abi_defs: bool,
20422033

20432034
_mach: PhantomData<M>,
20442035
}
@@ -2072,7 +2063,6 @@ impl<M: ABIMachineSpec> CallSite<M> {
20722063
is_tail_call,
20732064
caller_conv,
20742065
flags,
2075-
has_non_abi_defs: false,
20762066
_mach: PhantomData,
20772067
}
20782068
}
@@ -2096,7 +2086,6 @@ impl<M: ABIMachineSpec> CallSite<M> {
20962086
is_tail_call: IsTailCall::No,
20972087
caller_conv,
20982088
flags,
2099-
has_non_abi_defs: false,
21002089
_mach: PhantomData,
21012090
}
21022091
}
@@ -2120,7 +2109,6 @@ impl<M: ABIMachineSpec> CallSite<M> {
21202109
is_tail_call,
21212110
caller_conv,
21222111
flags,
2123-
has_non_abi_defs: false,
21242112
_mach: PhantomData,
21252113
}
21262114
}
@@ -2373,7 +2361,6 @@ impl<M: ABIMachineSpec> CallSite<M> {
23732361
vreg: into_reg,
23742362
location: RetLocation::Stack(amode, ty),
23752363
});
2376-
self.has_non_abi_defs = true;
23772364
into_regs.push(into_reg.to_reg());
23782365
}
23792366
}
@@ -2474,7 +2461,6 @@ impl<M: ABIMachineSpec> CallSite<M> {
24742461
callee_conv: call_conv,
24752462
caller_conv: self.caller_conv,
24762463
callee_pop_size,
2477-
has_non_abi_defs: self.has_non_abi_defs,
24782464
},
24792465
)
24802466
.into_iter()

cranelift/codegen/src/machinst/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ pub trait MachInst: Clone + Debug {
112112
/// Is this an "args" pseudoinst?
113113
fn is_args(&self) -> bool;
114114

115-
/// Should this instruction be included in the clobber-set?
115+
/// Should this instruction's clobber-list be included in the
116+
/// clobber-set?
116117
fn is_included_in_clobbers(&self) -> bool;
117118

118119
/// Does this instruction access memory?

cranelift/codegen/src/machinst/vcode.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,6 @@ impl<I: VCodeInst> VCode<I> {
672672
}
673673

674674
for (i, range) in self.operand_ranges.iter() {
675-
// Skip this instruction if not "included in clobbers" as
676-
// per the MachInst. (Some backends use this to implement
677-
// ABI specifics; e.g., excluding calls of the same ABI as
678-
// the current function from clobbers, because by
679-
// definition everything clobbered by the call can be
680-
// clobbered by this function without saving as well.)
681-
if !self.insts[i].is_included_in_clobbers() {
682-
continue;
683-
}
684-
685675
let operands = &self.operands[range.clone()];
686676
let allocs = &regalloc.allocs[range];
687677
for (operand, alloc) in operands.iter().zip(allocs.iter()) {
@@ -693,8 +683,28 @@ impl<I: VCodeInst> VCode<I> {
693683
}
694684

695685
// Also add explicitly-clobbered registers.
696-
if let Some(&inst_clobbered) = self.clobbers.get(&InsnIndex::new(i)) {
697-
clobbered.union_from(inst_clobbered);
686+
//
687+
// Skip merging this instruction's clobber list if not
688+
// "included in clobbers" as per the MachInst. (Some
689+
// backends use this to implement ABI specifics; e.g.,
690+
// excluding calls of the same ABI as the current function
691+
// from clobbers, because by definition everything
692+
// clobbered by the call can be clobbered by this function
693+
// without saving as well.
694+
//
695+
// This is important for a particular optimization: when
696+
// some registers are "half-clobbered", e.g. vector/float
697+
// registers on aarch64, we want them to be seen as
698+
// clobbered by regalloc so it avoids carrying values
699+
// across calls in these registers but not seen as
700+
// clobbered by prologue generation here (because the
701+
// actual half-clobber implied by the clobber list fits
702+
// within the clobbers that we allow without
703+
// clobber-saves).
704+
if self.insts[i].is_included_in_clobbers() {
705+
if let Some(&inst_clobbered) = self.clobbers.get(&InsnIndex::new(i)) {
706+
clobbered.union_from(inst_clobbered);
707+
}
698708
}
699709
}
700710

cranelift/filetests/filetests/isa/aarch64/tail-call-conv.clif

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -385,21 +385,13 @@ block0:
385385
; stp x23, x24, [sp, #-16]!
386386
; stp x21, x22, [sp, #-16]!
387387
; stp x19, x20, [sp, #-16]!
388-
; stp d14, d15, [sp, #-16]!
389-
; stp d12, d13, [sp, #-16]!
390-
; stp d10, d11, [sp, #-16]!
391-
; stp d8, d9, [sp, #-16]!
392388
; sub sp, sp, #240
393389
; block0:
394390
; mov x8, sp
395391
; load_ext_name x12, TestCase(%tail_callee_stack_rets)+0
396392
; blr x12
397393
; ldr x2, [sp, #232]
398394
; add sp, sp, #240
399-
; ldp d8, d9, [sp], #16
400-
; ldp d10, d11, [sp], #16
401-
; ldp d12, d13, [sp], #16
402-
; ldp d14, d15, [sp], #16
403395
; ldp x19, x20, [sp], #16
404396
; ldp x21, x22, [sp], #16
405397
; ldp x23, x24, [sp], #16
@@ -417,15 +409,11 @@ block0:
417409
; stp x23, x24, [sp, #-0x10]!
418410
; stp x21, x22, [sp, #-0x10]!
419411
; stp x19, x20, [sp, #-0x10]!
420-
; stp d14, d15, [sp, #-0x10]!
421-
; stp d12, d13, [sp, #-0x10]!
422-
; stp d10, d11, [sp, #-0x10]!
423-
; stp d8, d9, [sp, #-0x10]!
424412
; sub sp, sp, #0xf0
425-
; block1: ; offset 0x30
413+
; block1: ; offset 0x20
426414
; mov x8, sp
427-
; ldr x12, #0x3c
428-
; b #0x44
415+
; ldr x12, #0x2c
416+
; b #0x34
429417
; .byte 0x00, 0x00, 0x00, 0x00 ; reloc_external Abs8 %tail_callee_stack_rets 0
430418
; .byte 0x00, 0x00, 0x00, 0x00
431419
; blr x12
@@ -461,10 +449,6 @@ block0:
461449
; stur x9, [sp, #0xe8]
462450
; ldur x2, [sp, #0xe8]
463451
; add sp, sp, #0xf0
464-
; ldp d8, d9, [sp], #0x10
465-
; ldp d10, d11, [sp], #0x10
466-
; ldp d12, d13, [sp], #0x10
467-
; ldp d14, d15, [sp], #0x10
468452
; ldp x19, x20, [sp], #0x10
469453
; ldp x21, x22, [sp], #0x10
470454
; ldp x23, x24, [sp], #0x10
@@ -648,10 +632,6 @@ block0:
648632
; stp x23, x24, [sp, #-16]!
649633
; stp x21, x22, [sp, #-16]!
650634
; stp x19, x20, [sp, #-16]!
651-
; stp d14, d15, [sp, #-16]!
652-
; stp d12, d13, [sp, #-16]!
653-
; stp d10, d11, [sp, #-16]!
654-
; stp d8, d9, [sp, #-16]!
655635
; sub sp, sp, #400
656636
; block0:
657637
; movz x2, #10
@@ -705,10 +685,6 @@ block0:
705685
; blr x10
706686
; ldr x2, [sp, #392]
707687
; add sp, sp, #400
708-
; ldp d8, d9, [sp], #16
709-
; ldp d10, d11, [sp], #16
710-
; ldp d12, d13, [sp], #16
711-
; ldp d14, d15, [sp], #16
712688
; ldp x19, x20, [sp], #16
713689
; ldp x21, x22, [sp], #16
714690
; ldp x23, x24, [sp], #16
@@ -726,12 +702,8 @@ block0:
726702
; stp x23, x24, [sp, #-0x10]!
727703
; stp x21, x22, [sp, #-0x10]!
728704
; stp x19, x20, [sp, #-0x10]!
729-
; stp d14, d15, [sp, #-0x10]!
730-
; stp d12, d13, [sp, #-0x10]!
731-
; stp d10, d11, [sp, #-0x10]!
732-
; stp d8, d9, [sp, #-0x10]!
733705
; sub sp, sp, #0x190
734-
; block1: ; offset 0x30
706+
; block1: ; offset 0x20
735707
; mov x2, #0xa
736708
; mov x3, #0xf
737709
; mov x4, #0x14
@@ -779,8 +751,8 @@ block0:
779751
; stur x20, [sp, #0x90]
780752
; stur x22, [sp, #0x98]
781753
; add x8, sp, #0xa0
782-
; ldr x10, #0xf4
783-
; b #0xfc
754+
; ldr x10, #0xe4
755+
; b #0xec
784756
; .byte 0x00, 0x00, 0x00, 0x00 ; reloc_external Abs8 %tail_callee_stack_args_and_rets 0
785757
; .byte 0x00, 0x00, 0x00, 0x00
786758
; blr x10
@@ -817,10 +789,6 @@ block0:
817789
; str x9, [sp, #0x188]
818790
; ldr x2, [sp, #0x188]
819791
; add sp, sp, #0x190
820-
; ldp d8, d9, [sp], #0x10
821-
; ldp d10, d11, [sp], #0x10
822-
; ldp d12, d13, [sp], #0x10
823-
; ldp d14, d15, [sp], #0x10
824792
; ldp x19, x20, [sp], #0x10
825793
; ldp x21, x22, [sp], #0x10
826794
; ldp x23, x24, [sp], #0x10

0 commit comments

Comments
 (0)