[llvm-dev] Redundant load in llvm's codegen compares to gcc when accessing escaped pointer?

Chuang-Yu Cheng via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 15 07:58:22 PDT 2016


Hi,

Please look at this c code:

typedef struct _PB {
  void* data;  /* required.*/
  int   f1_;
  float f2_;
} PB;

PB** bar(PB** t);

void qux(PB* c) {
  bar(&c);              /* c is escaped because of bar */
  c->f1_ = 0;
  c->f2_ = 0.f;
}

// gcc-5.2.1 with -fno-strict-aliasing -O2 on x86
call    bar
movq    8(%rsp), %rax
movl    $0, 8(%rax)
movl    $0x00000000, 12(%rax)

// llvm 3.9.0 with -fno-strict-aliasing -O2 on x86
callq    bar
movq    (%rsp), %rax
movl    $0, 8(%rax)
movq    (%rsp), %rax
movl    $0, 12(%rax)

You can see that llvm load "c" twice, but gcc only load "c" once.
Of course, in bar function, you may do something very dangerous, e.g.

PB** bar(PB** t) {
   *t = (PB*) t;
}

But gcc doesn't care bar's definition.
Is llvm too conservative, or gcc too aggressive in this pattern?

Thanks for your help.

CY
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160315/b6dbf5bd/attachment.html>


More information about the llvm-dev mailing list