[llvm] f6b2c00 - [DebugInfo] Ensure that a demanded bits optimisation in

Chris Jackson via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 07:40:14 PDT 2020


Author: Chris Jackson
Date: 2020-03-30T15:39:22+01:00
New Revision: f6b2c003f360c3d0dcfe13d751805643f229f79b

URL: https://github.com/llvm/llvm-project/commit/f6b2c003f360c3d0dcfe13d751805643f229f79b
DIFF: https://github.com/llvm/llvm-project/commit/f6b2c003f360c3d0dcfe13d751805643f229f79b.diff

LOG: [DebugInfo]  Ensure that a demanded bits optimisation in
InstCombine does not result in an incorrect debuginfo variable
value

- Add an additional salvage and a test.

Reviewers: aprantl, djtodoro

Differential Revision: https://reviews.llvm.org/D76854

Bugzilla:  https://bugs.llvm.org/show_bug.cgi?id=44371

Added: 
    llvm/test/DebugInfo/X86/instcombine-demanded-bits-salvage.ll

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index a2437b3abe30..be5135e68ffd 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -87,6 +87,9 @@ bool InstCombiner::SimplifyDemandedBits(Instruction *I, unsigned OpNo,
   Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known,
                                           Depth, I);
   if (!NewVal) return false;
+  if (Instruction* OpInst = dyn_cast<Instruction>(U))
+    salvageDebugInfoOrMarkUndef(*OpInst);
+    
   replaceUse(U, NewVal);
   return true;
 }

diff  --git a/llvm/test/DebugInfo/X86/instcombine-demanded-bits-salvage.ll b/llvm/test/DebugInfo/X86/instcombine-demanded-bits-salvage.ll
new file mode 100644
index 000000000000..814a3bb8dc88
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/instcombine-demanded-bits-salvage.ll
@@ -0,0 +1,38 @@
+; RUN: opt -mtriple=x86_64-- %s -S --instcombine  -o - | FileCheck %s
+; Verify that demanded bits optimisations don't affect debuginfo 
+; variable values.
+; Bugzilla #44371
+
+ at a = common dso_local local_unnamed_addr global i32 0, align 4
+
+define dso_local i32 @p() local_unnamed_addr !dbg !11 {
+entry:
+  %conv = load i32, i32* @a, align 4, !dbg !14
+  %0 = and i32 %conv, 65535, !dbg !14
+  ; CHECK: metadata !DIExpression(DW_OP_constu, 65535, DW_OP_and, DW_OP_stack_value))
+  call void @llvm.dbg.value(metadata i32 %0, metadata !15, metadata !DIExpression()), !dbg !14
+  %1 = lshr i32 %0, 12, !dbg !14
+  %2 = and i32 %1, 8, !dbg !14
+  %3 = xor i32 %2, 8, !dbg !14
+  ret i32 0, !dbg !14
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!8, !9}
+!llvm.ident = !{!10}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, globals: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "instcomnine.ll", directory: "/temp/bz44371")
+!2 = !{}
+!3 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!8 = !{i32 7, !"Dwarf Version", i32 4}
+!9 = !{i32 2, !"Debug Info Version", i32 3}
+!10 = !{!""}
+!11 = distinct !DISubprogram(name: "p", scope: !1, file: !1, line: 6, type: !12, scopeLine: 6, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!12 = !DISubroutineType(types: !13)
+!13 = !{!7}
+!14 = !DILocation(line: 4, column: 35, scope: !11)
+!15 = !DILocalVariable(name: "p_28", arg: 1, scope: !11, file: !1, line: 16, type: !7)


        


More information about the llvm-commits mailing list