Skip to content

Clang generates worse code than GCC for a simple case #92649

Open
@KanRobert

Description

@KanRobert
int f(int *a) {
  if (*a & 1234)
    return 0;
  return 1;
}
bash$ gcc -O2 -S 1.c -o -
        .file   "1.c"
        .text
        .p2align 4
        .globl  f
        .type   f, @function
f:
.LFB0:
        .cfi_startproc
        xorl    %eax, %eax
        testl   $1234, (%rdi)
        sete    %al
        ret
bash$ clang -O2 -S 1.c -o -
        .text
        .file   "1.c"
        .globl  f                               # -- Begin function f
        .p2align        4, 0x90
        .type   f,@function
f:                                      # @f
        .cfi_startproc
# %bb.0:                                # %entry
        movzwl  (%rdi), %ecx
        xorl    %eax, %eax
        testl   $1234, %ecx                     # imm = 0x4D2
        sete    %al
        retq

https://www.godbolt.org/z/he4cj4a8G

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions