Index: llvm/include/llvm/CodeGen/StackMaps.h =================================================================== --- llvm/include/llvm/CodeGen/StackMaps.h +++ llvm/include/llvm/CodeGen/StackMaps.h @@ -267,6 +267,14 @@ Location() = default; Location(LocationType Type, unsigned Size, unsigned Reg, int64_t Offset) : Type(Type), Size(Size), Reg(Reg), Offset(Offset) {} + + bool isUndefReg() const { + return Type == Constant && Reg == 0 && Offset == 0xFEFEFEFE; + } + + static Location getUndefReg() { + return Location(Constant, sizeof(int64_t), 0, 0xFEFEFEFE); + } }; struct LiveOutReg { Index: llvm/lib/CodeGen/StackMaps.cpp =================================================================== --- llvm/lib/CodeGen/StackMaps.cpp +++ llvm/lib/CodeGen/StackMaps.cpp @@ -236,7 +236,7 @@ if (MOI->isUndef()) { // Record `undef` register as constant. Use same value as ISel uses. - Locs.emplace_back(Location::Constant, sizeof(int64_t), 0, 0xFEFEFEFE); + Locs.emplace_back(Location::getUndefReg()); return ++MOI; } @@ -481,7 +481,8 @@ for (auto &Loc : Locations) { // Constants are encoded as sign-extended integers. // -1 is directly encoded as .long 0xFFFFFFFF with no constant pool. - if (Loc.Type == Location::Constant && !isInt<32>(Loc.Offset)) { + if (Loc.Type == Location::Constant && !isInt<32>(Loc.Offset) && + !Loc.isUndefReg()) { Loc.Type = Location::ConstantIndex; // ConstPool is intentionally a MapVector of 'uint64_t's (as // opposed to 'int64_t's). We should never be in a situation @@ -546,7 +547,8 @@ if (opers.isAnyReg()) { unsigned NArgs = opers.getNumCallArgs(); for (unsigned i = 0, e = (opers.hasDef() ? NArgs + 1 : NArgs); i != e; ++i) - assert(Locations[i].Type == Location::Register && + assert((Locations[i].Type == Location::Register || + Locations[i].isUndefReg()) && "anyreg arg must be in reg."); } #endif Index: llvm/test/CodeGen/X86/stackmap-undef-operand-anyregcc.mir =================================================================== --- /dev/null +++ llvm/test/CodeGen/X86/stackmap-undef-operand-anyregcc.mir @@ -0,0 +1,61 @@ +# RUN: llc -mtriple=x86_64-apple-darwin -start-after=virtregrewriter -o - %s | FileCheck %s + +# Check there's no assertion for anyregcc with an undef operand to a stackmap. + +# CHECK: __LLVM_StackMaps: +# CHECK-NEXT: .byte 3 +# CHECK-NEXT: .byte 0 +# CHECK-NEXT: .short 0 +# CHECK-NEXT: .long 1 +# CHECK-NEXT: .long 0 +# CHECK-NEXT: .long 1 +# CHECK-NEXT: .quad _undef_anyregcc_patchpoint +# CHECK-NEXT: .quad 8 +# CHECK-NEXT: .quad 1 +# CHECK-NEXT: .quad 12 +# CHECK-NEXT: .long Ltmp0-_undef_anyregcc_patchpoint +# CHECK-NEXT: .short 0 +# CHECK-NEXT: .short 2 +# CHECK-NEXT: .byte 1 +# CHECK-NEXT: .byte 0 +# CHECK-NEXT: .short 8 +# CHECK-NEXT: .short 0 +# CHECK-NEXT: .short 0 +# CHECK-NEXT: .long 0 +# CHECK-NEXT: .byte 4 +# CHECK-NEXT: .byte 0 +# CHECK-NEXT: .short 8 +# CHECK-NEXT: .short 0 +# CHECK-NEXT: .short 0 +# CHECK-NEXT: .long 4278124286 +# CHECK-NEXT: .p2align 3 +# CHECK-NEXT: .short 0 +# CHECK-NEXT: .short 2 +# CHECK-NEXT: .short 0 +# CHECK-NEXT: .byte 0 +# CHECK-NEXT: .byte 8 +# CHECK-NEXT: .short 7 +# CHECK-NEXT: .byte 0 +# CHECK-NEXT: .byte 8 +# CHECK-NEXT: .p2align 3 +--- +name: undef_anyregcc_patchpoint +tracksRegLiveness: true +frameInfo: + hasPatchPoint: true + hasCalls: true +fixedStack: + - { id: 0, type: default, offset: 72, size: 8, alignment: 8, stack-id: default, + isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true, + debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } +body: | + bb.0: + liveins: $rcx, $rdi, $rdx, $rsi, $r8, $r9 + + ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp + dead renamable $rax = MOV64rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (load (s64) from %fixed-stack.0) + renamable $rax = PATCHPOINT 12, 15, 0, 1, 13, undef renamable $rax, csr_64_allregs, implicit-def dead early-clobber $r11, implicit-def $rsp, implicit-def $ssp + ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp + RET 0, $rax + +... Index: llvm/test/CodeGen/X86/statepoint-fixup-undef.mir =================================================================== --- llvm/test/CodeGen/X86/statepoint-fixup-undef.mir +++ llvm/test/CodeGen/X86/statepoint-fixup-undef.mir @@ -124,12 +124,11 @@ ; STACKMAP: .byte 0 ; STACKMAP: .short 0 ; STACKMAP: .long 1 - ; STACKMAP: .long 1 + ; STACKMAP: .long 0 ; STACKMAP: .long 1 ; STACKMAP: .quad test_undef ; STACKMAP: .quad 88 ; STACKMAP: .quad 1 - ; STACKMAP: .quad 4278124286 ; STACKMAP: .quad 2 ; STACKMAP: .long .Ltmp0-test_undef ; STACKMAP: .short 0 @@ -182,13 +181,13 @@ ; STACKMAP: .short 3 ; STACKMAP: .short 0 ; STACKMAP: .long 0 - ; This is entry we're looking for, reference to constant pool entry 0xFEFEFEFE - ; STACKMAP: .byte 5 + ; This is entry we're looking for, reference to constant entry 0xFEFEFEFE + ; STACKMAP: .byte 4 ; STACKMAP: .byte 0 ; STACKMAP: .short 8 ; STACKMAP: .short 0 ; STACKMAP: .short 0 - ; STACKMAP: .long 0 + ; STACKMAP: .long 4278124286 ; STACKMAP: .byte 4 ; STACKMAP: .byte 0 ; STACKMAP: .short 8