Index: llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -181,8 +181,15 @@ void DwarfExpression::addUnsignedConstant(uint64_t Value) { assert(LocationKind == Implicit || LocationKind == Unknown); LocationKind = Implicit; - emitOp(dwarf::DW_OP_constu); - emitUnsigned(Value); + if (Value < 32) + emitOp(dwarf::DW_OP_lit0 + Value); + else if (Value == 0xfffffff) { + emitOp(dwarf::DW_OP_lit0); + emitOp(dwarf::DW_OP_not); + } else { + emitOp(dwarf::DW_OP_constu); + emitUnsigned(Value); + } } void DwarfExpression::addUnsignedConstant(const APInt &Value) { Index: llvm/test/DebugInfo/ARM/PR26163.ll =================================================================== --- llvm/test/DebugInfo/ARM/PR26163.ll +++ llvm/test/DebugInfo/ARM/PR26163.ll @@ -9,8 +9,8 @@ ; CHECK: DW_TAG_inlined_subroutine ; CHECK: DW_TAG_variable ; CHECK: DW_AT_location [DW_FORM_sec_offset] ({{.*}} -; CHECK: [0x00000004, 0x00000004): DW_OP_constu 0x0, DW_OP_stack_value, DW_OP_piece 0x8 -; CHECK: [0x00000004, 0x00000014): DW_OP_constu 0x0, DW_OP_stack_value, DW_OP_piece 0x4) +; CHECK: [0x00000004, 0x00000004): DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x8 +; CHECK: [0x00000004, 0x00000014): DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x4) ; Created form the following test case (PR26163) with ; clang -cc1 -triple armv4t--freebsd11.0-gnueabi -emit-obj -debug-info-kind=standalone -O2 -x c test.c Index: llvm/test/DebugInfo/ARM/split-complex.ll =================================================================== --- llvm/test/DebugInfo/ARM/split-complex.ll +++ llvm/test/DebugInfo/ARM/split-complex.ll @@ -14,7 +14,7 @@ ; The target has no native double type. ; SROA split the complex value into two i64 values. ; CHECK: DW_TAG_formal_parameter - ; CHECK-NEXT: DW_AT_location [DW_FORM_block1] (DW_OP_constu 0x0, DW_OP_piece 0x8) + ; CHECK-NEXT: DW_AT_location [DW_FORM_block1] (DW_OP_lit0, DW_OP_piece 0x8) ; CHECK-NEXT: DW_AT_name {{.*}} "c" tail call void @llvm.dbg.value(metadata i64 0, metadata !14, metadata !17), !dbg !16 ; Manually removed to disable location list emission: Index: llvm/test/DebugInfo/Generic/incorrect-variable-debugloc1.ll =================================================================== --- llvm/test/DebugInfo/Generic/incorrect-variable-debugloc1.ll +++ llvm/test/DebugInfo/Generic/incorrect-variable-debugloc1.ll @@ -1,6 +1,6 @@ ; REQUIRES: object-emission ; This test is failing for powerpc64, because a location list for the -; variable 'c' is not generated at all. Temporary marking this test as XFAIL +; variable 'c' is not generated at all. Temporary marking this test as XFAIL ; for powerpc, until PR21881 is fixed. ; XFAIL: powerpc64 @@ -9,13 +9,14 @@ ; RUN: %llc_dwarf -O2 -dwarf-version 4 -filetype=obj < %s | llvm-dwarfdump - | FileCheck %s --check-prefix=DWARF4 ; This is a test for PR21176. -; DW_OP_const doesn't describe a constant value, but a value at a constant address. +; DW_OP_const doesn't describe a constant value, but a value at a constant address. ; The proper way to describe a constant value is DW_OP_constu , DW_OP_stack_value. +; For values < 32 we emit the canonical DW_OP_lit. ; Generated with clang -S -emit-llvm -g -O2 test.cpp ; extern int func(); -; +; ; int main() ; { ; volatile int c = 13; @@ -26,8 +27,8 @@ ; CHECK: DW_TAG_variable ; CHECK: DW_AT_location ; CHECK-NOT: DW_AT -; DWARF23: DW_OP_constu 0xd{{$}} -; DWARF4: DW_OP_constu 0xd, DW_OP_stack_value{{$}} +; DWARF23: DW_OP_lit13{{$}} +; DWARF4: DW_OP_lit13, DW_OP_stack_value{{$}} ; Function Attrs: uwtable define i32 @main() #0 !dbg !4 { Index: llvm/test/DebugInfo/X86/PR26148.ll =================================================================== --- llvm/test/DebugInfo/X86/PR26148.ll +++ llvm/test/DebugInfo/X86/PR26148.ll @@ -19,8 +19,8 @@ ; AS in 26163, we expect two ranges (as opposed to one), the first one being zero sized ; ; -; CHECK: [0x0000000000000004, 0x0000000000000004): DW_OP_constu 0x3, DW_OP_piece 0x4, DW_OP_reg5 RDI, DW_OP_piece 0x2 -; CHECK: [0x0000000000000004, 0x0000000000000014): DW_OP_constu 0x3, DW_OP_piece 0x4, DW_OP_constu 0x0, DW_OP_piece 0x4 +; CHECK: [0x0000000000000004, 0x0000000000000004): DW_OP_lit3, DW_OP_piece 0x4, DW_OP_reg5 RDI, DW_OP_piece 0x2 +; CHECK: [0x0000000000000004, 0x0000000000000014): DW_OP_lit3, DW_OP_piece 0x4, DW_OP_lit0, DW_OP_piece 0x4 source_filename = "test/DebugInfo/X86/PR26148.ll" target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" Index: llvm/test/DebugInfo/X86/constant-loclist.ll =================================================================== --- llvm/test/DebugInfo/X86/constant-loclist.ll +++ llvm/test/DebugInfo/X86/constant-loclist.ll @@ -14,7 +14,7 @@ ; CHECK-NEXT: DW_AT_name {{.*}}"i" ; CHECK: DW_TAG_variable ; CHECK-NEXT: DW_AT_location [DW_FORM_data4] ( -; CHECK-NEXT: [0x{{.*}}, 0x{{.*}}): DW_OP_constu 0x0 +; CHECK-NEXT: [0x{{.*}}, 0x{{.*}}): DW_OP_lit0 ; CHECK-NEXT: [0x{{.*}}, 0x{{.*}}): DW_OP_constu 0x4000000000000000) ; CHECK-NEXT: DW_AT_name {{.*}}"u" Index: llvm/test/DebugInfo/X86/partial-constant.ll =================================================================== --- llvm/test/DebugInfo/X86/partial-constant.ll +++ llvm/test/DebugInfo/X86/partial-constant.ll @@ -18,7 +18,7 @@ ; CHECK-NOT: DW_AT_const_value ; CHECK: .debug_loc contents: ; CHECK-NEXT: 0x00000000: -; CHECK-NEXT: {{.*}}: DW_OP_constu 0x1, DW_OP_stack_value +; CHECK-NEXT: {{.*}}: DW_OP_lit1, DW_OP_stack_value source_filename = "test.ii" target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" Index: llvm/test/DebugInfo/X86/pieces-4.ll =================================================================== --- llvm/test/DebugInfo/X86/pieces-4.ll +++ llvm/test/DebugInfo/X86/pieces-4.ll @@ -25,7 +25,7 @@ ; DWARF: .debug_loc contents: ; DWARF-NEXT: 0x00000000: -; DWARF-NEXT: {{.*}}: DW_OP_breg7 RSP+{{[0-9]+}}, DW_OP_piece 0x4, DW_OP_constu 0x0, DW_OP_stack_value, DW_OP_piece 0x4 +; DWARF-NEXT: {{.*}}: DW_OP_breg7 RSP+{{[0-9]+}}, DW_OP_piece 0x4, DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x4 ; ModuleID = 't.c' source_filename = "t.c" Index: llvm/test/DebugInfo/X86/stack-value-piece.ll =================================================================== --- llvm/test/DebugInfo/X86/stack-value-piece.ll +++ llvm/test/DebugInfo/X86/stack-value-piece.ll @@ -19,21 +19,21 @@ ; CHECK: DW_AT_name {{.*}} "i" ; CHECK: DW_TAG_variable ; CHECK-NEXT: DW_AT_location {{.*}} ([[I:.*]] -; CHECK-NEXT: [{{.*}}, {{.*}}): DW_OP_reg5 RDI, DW_OP_piece 0x4, DW_OP_constu 0x0, DW_OP_stack_value, DW_OP_piece 0x4) +; CHECK-NEXT: [{{.*}}, {{.*}}): DW_OP_reg5 RDI, DW_OP_piece 0x4, DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x4) ; CHECK-NEXT: DW_AT_name {{.*}} "r" ; ; CHECK: DW_TAG_subprogram ; CHECK: DW_AT_name {{.*}} "f" ; CHECK: DW_TAG_variable ; CHECK-NEXT: DW_AT_location {{.*}} ([[F:.*]] -; CHECK-NEXT: [{{.*}}, {{.*}}): DW_OP_reg17 XMM0, DW_OP_piece 0x4, DW_OP_constu 0x0, DW_OP_stack_value, DW_OP_piece 0x4) +; CHECK-NEXT: [{{.*}}, {{.*}}): DW_OP_reg17 XMM0, DW_OP_piece 0x4, DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x4) ; CHECK-NEXT: DW_AT_name {{.*}} "r" ; ; CHECK: .debug_loc contents: ; CHECK: [[I]]: -; CHECK-NEXT: [{{.*}}, {{.*}}): DW_OP_reg5 RDI, DW_OP_piece 0x4, DW_OP_constu 0x0, DW_OP_stack_value, DW_OP_piece 0x4 +; CHECK-NEXT: [{{.*}}, {{.*}}): DW_OP_reg5 RDI, DW_OP_piece 0x4, DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x4 ; CHECK: [[F]]: -; CHECK-NEXT: [{{.*}}, {{.*}}): DW_OP_reg17 XMM0, DW_OP_piece 0x4, DW_OP_constu 0x0, DW_OP_stack_value, DW_OP_piece 0x4 +; CHECK-NEXT: [{{.*}}, {{.*}}): DW_OP_reg17 XMM0, DW_OP_piece 0x4, DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x4 source_filename = "stack-value-piece.c" target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"