Skip to content

dead function call is not removed in branch comparing global variable addresses #48778

@thetheodor

Description

@thetheodor
Bugzilla Link 49434
Version trunk
OS Linux
CC @ttheodor

Extended Description

~/llvm-project/build/bin/clang -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git d2000b4)
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,@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,@object # @​a
.bss
.globl a
a:
.byte 0 # 0x0
.size a, 1

.type	b,@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","",@progbits
.addrsig
.addrsig_sym a
.addrsig_sym b

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions