[PATCH] D80691: Proposed fix for PR46114

Qirun Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 28 07:02:36 PDT 2020


helloqirun added a comment.

Hi @Orlando

> During EarlyCSE we detect that `%0 = load i32, i32* @a` is the same as 
>  `%1 = load i32, i32* @a`, so the latter is removed. We rewrite the dbg.value
>  which uses %1 to use %0 instead, because %1 is being removed. IIUC this
>  behaviour in EarlyCSE looks correct, and makes me feel like the issue
>  comes from somewhere else?

There are cases where EarlyCSE needs to remove the first (the following case). The instruction ``%0 = load i32, i32* @a, align 4`` can be the product of both EarlyCSE DCE (the following case) and EarlyCSE CSE LOAD (the case in the original PR).

The EarlyCSE DCE case is compatible with the current logic in `RemoveRedundantDbgInstrs'.  So I propose to patch the EarlyCSE CSE LOAD case.

Consider the following test case

  $ cat abc1.c
  int a = 1;
  short b;
  char c;
  int main() {
    int d = a, l_52 = 0;
    b = (l_52 = a) - c; 
     {
      int e=d;
    }
  }

The IR before EarlyCSE is (which is the same as my original PR)

  %0 = load i32, i32* @a, align 4, !dbg !25, !tbaa !26
  call void @llvm.dbg.value(metadata i32 %0, metadata !21, metadata !DIExpression()), !dbg !30
  call void @llvm.dbg.value(metadata i32 0, metadata !22, metadata !DIExpression()), !dbg !30
    %1 = load i32, i32* @a, align 4, !dbg !31, !tbaa !26
  call void @llvm.dbg.value(metadata i32 %1, metadata !22, metadata !DIExpression()), !dbg !30
  %2 = load i8, i8* @c, align 1, !dbg !32, !tbaa !33
  %conv = sext i8 %2 to i32, !dbg !32
  ...

The IR after EarlyCSE is

  call void @llvm.dbg.value(metadata i32 undef, metadata !21, metadata !DIExpression()), !dbg !25
  call void @llvm.dbg.value(metadata i32 0, metadata !22, metadata !DIExpression()), !dbg !25
  %0 = load i32, i32* @a, align 4, !dbg !26, !tbaa !27
  call void @llvm.dbg.value(metadata i32 %0, metadata !22, metadata !DIExpression()), !dbg !25
  %1 = load i8, i8* @c, align 1, !dbg !31, !tbaa !32
  %conv = sext i8 %1 to i32, !dbg !31

In this case, `removeRedundantDbgInstrsUsingBackwardScan` will remove the last `dbg.value`. So lldb can print the correct value.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80691/new/

https://reviews.llvm.org/D80691





More information about the llvm-commits mailing list