[llvm-bugs] [Bug 36959] New: TBAA fails to disambiguate pointers, missed redundancy elimination

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 30 11:27:38 PDT 2018


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

            Bug ID: 36959
           Summary: TBAA fails to disambiguate pointers, missed redundancy
                    elimination
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: sebpop at gmail.com
                CC: llvm-bugs at lists.llvm.org

typedef struct {
  const char *data;
  int length;
} str;

typedef struct {
  str *s;
} a;

typedef struct {
  const char *s;
} b;

void fun(a *in, b *out) {
  out->s = in->s->data;
  out->s = in->s->data;
}

GCC finds the redundancy and reads and writes only once (for aarch64):
fun:
        ldr     x0, [x0]
        ldr     x0, [x0]
        str     x0, [x1]
        ret

LLVM generates twice the number of loads and stores than GCC:
fun:
        ldr     x8, [x0]
        ldr     x8, [x8]
        str     x8, [x1]
        ldr     x8, [x0]
        ldr     x8, [x8]
        str     x8, [x1]
        ret

This may be related to https://bugs.llvm.org/show_bug.cgi?id=35703
Here is the llvm IR for the testcase:

%struct.a = type { %struct.str* }
%struct.str = type { i8*, i32 }
%struct.b = type { i8* }

define dso_local void @fun(%struct.a* nocapture readonly %in, %struct.b*
nocapture %out) local_unnamed_addr #0 {
entry:
  %0 = bitcast %struct.a* %in to i64**
  %1 = load i64*, i64** %0, align 8, !tbaa !2
  %2 = load i64, i64* %1, align 8, !tbaa !7
  %3 = bitcast %struct.b* %out to i64*
  store i64 %2, i64* %3, align 8, !tbaa !2
  %4 = load i64*, i64** %0, align 8, !tbaa !2
  %5 = load i64, i64* %4, align 8, !tbaa !7
  store i64 %5, i64* %3, align 8, !tbaa !2
  ret void
}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 7.0.0 "}
!2 = !{!3, !4, i64 0}
!3 = !{!"", !4, i64 0}
!4 = !{!"any pointer", !5, i64 0}
!5 = !{!"omnipotent char", !6, i64 0}
!6 = !{!"Simple C/C++ TBAA"}
!7 = !{!8, !4, i64 0}
!8 = !{!"", !4, i64 0, !9, i64 8}
!9 = !{!"int", !5, i64 0}

-- 
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/20180330/afc57ae0/attachment-0001.html>


More information about the llvm-bugs mailing list