Skip to content

Commit 0ef7437

Browse files
authored
[SelectionDAG][Statepoint] Fix truncation of gc.statepoint ID argument (#85908)
The ID argument of `gc.statepoint` gets incorrectly truncated to 32 bits during code generation. This is fixed by using `uint64_t` instead of `unsigned` for the `ID` member in `SelectionDAGBuilder::StatepointLoweringInfo`, and a `patchpoint` test case is extended to check for 64 bit ID generation in stackmaps.
1 parent 0b9528d commit 0ef7437

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class SelectionDAGBuilder {
449449
ArrayRef<const Use> GCTransitionArgs;
450450

451451
/// The ID that the resulting STATEPOINT instruction has to report.
452-
unsigned ID = -1;
452+
uint64_t ID = -1;
453453

454454
/// Information regarding the underlying call instruction.
455455
TargetLowering::CallLoweringInfo CLI;

llvm/test/CodeGen/AArch64/stackmap.ll

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
; CHECK-NEXT: .byte 0
1010
; CHECK-NEXT: .hword 0
1111
; Num Functions
12-
; CHECK-NEXT: .word 14
12+
; CHECK-NEXT: .word 15
1313
; Num LargeConstants
1414
; CHECK-NEXT: .word 4
1515
; Num Callsites
16-
; CHECK-NEXT: .word 18
16+
; CHECK-NEXT: .word 22
1717

1818
; Functions and stack size
1919
; CHECK-NEXT: .xword constantargs
@@ -49,6 +49,9 @@
4949
; CHECK-NEXT: .xword longid
5050
; CHECK-NEXT: .xword 16
5151
; CHECK-NEXT: .xword 4
52+
; CHECK-NEXT: .xword statepoint_longid
53+
; CHECK-NEXT: .xword 16
54+
; CHECK-NEXT: .xword 4
5255
; CHECK-NEXT: .xword clobberLR
5356
; CHECK-NEXT: .xword 112
5457
; CHECK-NEXT: .xword 1
@@ -443,6 +446,26 @@ entry:
443446
ret void
444447
}
445448

449+
; Test a 64-bit ID for statepoint.
450+
;
451+
; CHECK: .xword 4294967295
452+
; CHECK-LABEL: .word .L{{.*}}-statepoint_longid
453+
; CHECK: .xword 4294967296
454+
; CHECK-LABEL: .word .L{{.*}}-statepoint_longid
455+
; CHECK: .xword 9223372036854775807
456+
; CHECK-LABEL: .word .L{{.*}}-statepoint_longid
457+
; CHECK: .xword -1
458+
; CHECK-LABEL: .word .L{{.*}}-statepoint_longid
459+
define void @statepoint_longid() gc "statepoint-example" {
460+
entry:
461+
%safepoint_token1 = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 4294967295, i32 0, ptr elementtype(void ()) @return_void, i32 0, i32 0, i32 0, i32 0)
462+
%safepoint_token2 = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 4294967296, i32 0, ptr elementtype(void ()) @return_void, i32 0, i32 0, i32 0, i32 0)
463+
%safepoint_token3 = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 9223372036854775807, i32 0, ptr elementtype(void ()) @return_void, i32 0, i32 0, i32 0, i32 0)
464+
%safepoint_token4 = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 -1, i32 0, ptr elementtype(void ()) @return_void, i32 0, i32 0, i32 0, i32 0)
465+
ret void
466+
}
467+
declare void @return_void()
468+
446469
; Map a value when R11 is the only free register.
447470
; The scratch register should not be used for a live stackmap value.
448471
;
@@ -463,8 +486,8 @@ define void @clobberLR(i32 %a) {
463486
ret void
464487
}
465488

466-
; A stack frame which needs to be realigned at runtime (to meet alignment
467-
; criteria for values on the stack) does not have a fixed frame size.
489+
; A stack frame which needs to be realigned at runtime (to meet alignment
490+
; criteria for values on the stack) does not have a fixed frame size.
468491
; CHECK-LABEL: .word .L{{.*}}-needsStackRealignment
469492
; CHECK-NEXT: .hword 0
470493
; 0 locations
@@ -537,3 +560,4 @@ define void @floats(float %f, double %g) {
537560
declare void @llvm.experimental.stackmap(i64, i32, ...)
538561
declare void @llvm.experimental.patchpoint.void(i64, i32, ptr, i32, ...)
539562
declare i64 @llvm.experimental.patchpoint.i64(i64, i32, ptr, i32, ...)
563+
declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)

0 commit comments

Comments
 (0)