From 0e79ba4a678ccfdb13e906fa3c695cde7c359131 Mon Sep 17 00:00:00 2001 From: Markus Lavin Date: Mon, 6 May 2019 07:20:56 +0000 Subject: [PATCH] [DebugInfo] GlobalOpt DW_OP_deref_size instead of DW_OP_deref. Optimization pass lib/Transforms/IPO/GlobalOpt.cpp needs to insert DW_OP_deref_size instead of DW_OP_deref to be compatible with big-endian targets for same reasons as in D59687. Differential Revision: https://reviews.llvm.org/D60611 llvm-svn: 360013 --- llvm/lib/Transforms/IPO/GlobalOpt.cpp | 8 ++++++-- llvm/test/Transforms/GlobalOpt/integer-bool-dwarf.ll | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 4d2b0178612a2..2a869444d6ef0 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -1654,6 +1654,9 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { for(auto *GVe : GVs){ DIGlobalVariable *DGV = GVe->getVariable(); DIExpression *E = GVe->getExpression(); + const DataLayout &DL = GV->getParent()->getDataLayout(); + unsigned SizeInOctets = + DL.getTypeAllocSizeInBits(NewGV->getType()->getElementType()) / 8; // It is expected that the address of global optimized variable is on // top of the stack. After optimization, value of that variable will @@ -1664,8 +1667,9 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { // DW_OP_deref DW_OP_constu // DW_OP_mul DW_OP_constu DW_OP_plus DW_OP_stack_value SmallVector Ops = { - dwarf::DW_OP_deref, dwarf::DW_OP_constu, ValMinus, - dwarf::DW_OP_mul, dwarf::DW_OP_constu, ValInit, + dwarf::DW_OP_deref_size, SizeInOctets, + dwarf::DW_OP_constu, ValMinus, + dwarf::DW_OP_mul, dwarf::DW_OP_constu, ValInit, dwarf::DW_OP_plus}; E = DIExpression::prependOpcodes(E, Ops, DIExpression::WithStackValue); DIGlobalVariableExpression *DGVE = diff --git a/llvm/test/Transforms/GlobalOpt/integer-bool-dwarf.ll b/llvm/test/Transforms/GlobalOpt/integer-bool-dwarf.ll index 6aa35be21d862..64fee228fed89 100644 --- a/llvm/test/Transforms/GlobalOpt/integer-bool-dwarf.ll +++ b/llvm/test/Transforms/GlobalOpt/integer-bool-dwarf.ll @@ -2,7 +2,7 @@ ;CHECK: @foo = internal unnamed_addr global i1 false, align 4, !dbg ![[VAR:.*]] ;CHECK: ![[VAR]] = !DIGlobalVariableExpression(var: !1, expr: -;CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_constu, 111, DW_OP_mul, +;CHECK-SAME: !DIExpression(DW_OP_deref_size, 1, DW_OP_constu, 111, DW_OP_mul, ;CHECK-SAME: DW_OP_constu, 0, DW_OP_plus, DW_OP_stack_value, ;CHECK-SAME: DW_OP_LLVM_fragment, 0, 1))