[llvm-bugs] [Bug 49434] New: dead function call is not removed in branch comparing global variable addresses

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 4 04:30:50 PST 2021


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

            Bug ID: 49434
           Summary: dead function call is not removed in branch comparing
                    global variable addresses
           Product: tools
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: opt
          Assignee: unassignedbugs at nondot.org
          Reporter: theodoridisgr at gmail.com
                CC: llvm-bugs at lists.llvm.org

~/llvm-project/build/bin/clang -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git
d2000b45d033c06dc7973f59909a0ad12887ff51)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/theo/llvm-project/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/10.2.0
Selected GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/10.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Found CUDA installation: /opt/cuda, version 11.2

--------------------------------------------------------------------------------

cat test.c
char a, b[2];

extern void foo (void);
int main() {
 char *c = &a, *d = &b[1];
 if (c == d)
  foo();
 return 0;
}

--------------------------------------------------------------------------------

~/llvm-project/build/bin/clang -O3 -S -o /dev/stdout test.c
        .text
        .file   "test.c"
        .globl  main                            # -- Begin function main
        .p2align        4, 0x90
        .type   main, at function
main:                                   # @main
        .cfi_startproc
# %bb.0:                                # %entry
        movl    $b+1, %eax
        cmpq    $a, %rax
        jne     .LBB0_2
# %bb.1:                                # %if.then
        pushq   %rax
        .cfi_def_cfa_offset 16
        callq   foo
        addq    $8, %rsp
        .cfi_def_cfa_offset 8
.LBB0_2:                                # %if.end
        xorl    %eax, %eax
        retq
.Lfunc_end0:
        .size   main, .Lfunc_end0-main
        .cfi_endproc
                                        # -- End function
        .type   a, at object                       # @a
        .bss
        .globl  a
a:
        .byte   0                               # 0x0
        .size   a, 1

        .type   b, at object                       # @b
        .globl  b
b:
        .zero   2
        .size   b, 2

        .ident  "clang version 13.0.0 (https://github.com/llvm/llvm-project.git
d2000b45d033c06dc7973f59909a0ad12887ff51)"
        .section        ".note.GNU-stack","", at progbits
        .addrsig
        .addrsig_sym a
        .addrsig_sym b

--------------------------------------------------------------------------------

if *d = &b[1]; is replaced with *d=b, the dead branch is properly DCE'd.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210304/a2970c5a/attachment-0001.html>


More information about the llvm-bugs mailing list