[LLVMbugs] [Bug 20074] New: Redundant loads not removed

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jun 18 02:36:09 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20074

            Bug ID: 20074
           Summary: Redundant loads not removed
           Product: tools
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: opt
          Assignee: unassignedbugs at nondot.org
          Reporter: ssijaric at codeaurora.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Compiling the following using "clang --target=aarch64-linux-gnu  a.c -O3 -c -S"

typedef struct AStruct {
  char a;
  char b;
  char c[10];
} * AS;

extern AS aStruct;

int
main()
{
  aStruct->a = 'a';
  aStruct->c[2] = 'c';
  aStruct->b = 'b';
  return 0;
}


results in:

main:                                   // @main
// BB#0:                                // %entry
        adrp    x8, aStruct
        ldr     x9, [x8, :lo12:aStruct]  <====
        movz    w10, #0x61
        movz    w11, #0x63
        strb     w10, [x9]
        strb    w11, [x9, #4]
        ldr     x8, [x8, :lo12:aStruct]  <===== redundant load
        movz    w9, #0x62
        strb    w9, [x8, #1]
        mov      w0, wzr
        ret


GVN sees the following:

define i32 @main() #0 {
entry:
  %0 = load %struct.AStruct** @aStruct, align 8, !tbaa !1
  %a = getelementptr inbounds %struct.AStruct* %0, i64 0, i32 0
  store i8 97, i8* %a, align 1, !tbaa !5
  %1 = load %struct.AStruct** @aStruct, align 8, !tbaa !1
  %arrayidx = getelementptr inbounds %struct.AStruct* %1, i64 0, i32 2, i64 2
  store i8 99, i8* %arrayidx, align 1, !tbaa !7
  %2 = load %struct.AStruct** @aStruct, align 8, !tbaa !1
  %b = getelementptr inbounds %struct.AStruct* %2, i64 0, i32 1
  store i8 98, i8* %b, align 1, !tbaa !8
  ret i32 0
}



with 

!0 = metadata !{metadata !"clang version 3.5.0 "}
!1 = metadata !{metadata !2, metadata !2, i64 0}
!2 = metadata !{metadata !"any pointer", metadata !3, i64 0}
!3 = metadata !{metadata !"omnipotent char", metadata !4, i64 0}
!4 = metadata !{metadata !"Simple C/C++ TBAA"}
!5 = metadata !{metadata !6, metadata !3, i64 0}
!6 = metadata !{metadata !"AStruct", metadata !3, i64 0, metadata !3, i64 1,
metadata !3, i64 2}
!7 = metadata !{metadata !3, metadata !3, i64 0}
!8 = metadata !{metadata !6, metadata !3, i64 1}



where alias analysis tells it that 


store i8 99, i8* %arrayidx, align 1, !tbaa !7

clobbers

%2 = load %struct.AStruct** @aStruct, align 8, !tbaa !1


Changing the above example to

typedef struct AStruct {
  char a;
  char b;
  char c;
} * AS;

extern AS aStruct;

int
main()
{
  aStruct->a = 'a';
  aStruct->c = 'c';
  aStruct->b = 'b';
  return 0;
}


results in all redundant loads being removed.

Gcc 4.9 removes all redundant loads in the first case.

-- 
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/20140618/7fca591b/attachment.html>


More information about the llvm-bugs mailing list