[llvm-bugs] [Bug 40605] New: -ftrivial-auto-var-init creates big redundant structs in .rodata

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 5 05:32:00 PST 2019


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

            Bug ID: 40605
           Summary: -ftrivial-auto-var-init creates big redundant structs
                    in .rodata
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: glider at google.com
                CC: dvyukov at google.com, kcc at google.com,
                    llvm-bugs at lists.llvm.org, llvm-bugzilla at jfbastien.com

When wiping uninitialized C structures with a 0xAA pattern in the
-ftrivial-auto-var-init=pattern mode Clang generates big constant structures
that end up in .rodata.
E.g. for the following case:

struct S {
  void *p1, *p2, *p3, *p4;
};

extern void bar(struct S *s);

void foo() {
  struct S local;
  bar(&local);
}

we generate the following IR:

=====================
@__const.foo.local = private unnamed_addr constant %struct.S { i8* inttoptr
(i64 -6148914691236517206 to i8*), i8* inttoptr (i64 -6148914691236517206 to
i8*), i8* inttoptr (i64 -6148914691236517206 to i8*), i8* inttoptr (i64
-6148914691236517206 to i8*) }, align 8
...
define dso_local void @foo() local_unnamed_addr #0 {
  %1 = alloca %struct.S, align 8 
  %2 = bitcast %struct.S* %1 to i8*
  call void @llvm.lifetime.start.p0i8(i64 32, i8* nonnull %2) #3
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 %2, i8* align 8
bitcast (%struct.S* @__const.foo.local to i8*), i64 32, i1 false)
  call void @bar(%struct.S* nonnull %1) #3
  call void @llvm.lifetime.end.p0i8(i64 32, i8* nonnull %2) #3
  ret void 
}
=====================

, which ends up translated into the following assembly code:

=====================
foo:                                    # @foo
        .cfi_startproc
# %bb.0:
        subq    $40, %rsp
        .cfi_def_cfa_offset 48
        movups  .L__const.foo.local+16(%rip), %xmm0
        movaps  %xmm0, 16(%rsp)
        movups  .L__const.foo.local(%rip), %xmm0
        movaps  %xmm0, (%rsp)
        movq    %rsp, %rdi
        callq   bar 
        addq    $40, %rsp
        .cfi_def_cfa_offset 8
        retq
.Lfunc_end0:
        .size   foo, .Lfunc_end0-foo
        .cfi_endproc
=====================

So the instrumentation produces big volumes of 0xAA constants in .rodata
instead of at most one 16-byte 0xAA constant that's used all over the place.

Most certainly Clang is also unable to split copying of those big structs,
which results in missed dead store elimination opportunities.

-- 
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/20190205/8576a969/attachment.html>


More information about the llvm-bugs mailing list