[llvm-bugs] [Bug 31844] New: Many small consecutive moves of constants aren't optimized into something better.

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Feb 1 16:12:34 PST 2017


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

            Bug ID: 31844
           Summary: Many small consecutive moves of constants aren't
                    optimized into something better.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: george.burgess.iv at gmail.com
          Reporter: george.burgess.iv at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Motivating example: https://godbolt.org/g/VOk6W6

Danny noted that test2 gets turned into good code because clang emits an
intermediate alloca to write the {0, 1, ...} array to, whereas in test1, {0, 1,
...} gets written directly to an sret param. As a result, SROA was able to work
on test2, but not test1.

The idea at the moment is that we should just make MemCpyOpt handle this; it's
happy to turn consecutive stores of the same value into a memset, but isn't
currently able to turn consecutive stores of different values into a memcpy:
http://llvm.org/docs/doxygen/html/MemCpyOptimizer_8cpp_source.html#l00626 .

I'm happy to see what I can do here, but this isn't at the top of my list. So,
if someone else wants to jump on this, feel free. :)

(Mildly verbose) repro: running `opt -O2` on the following code is effectively
a nop.

%struct.FooContainer = type { i16, %struct.Foo, i16 }
%struct.Foo = type { [16 x i8] }

; Function Attrs: norecurse nounwind uwtable
define void @_Z5test1v(%struct.FooContainer* noalias nocapture sret
%agg.result) local_unnamed_addr {
entry:
  %a = getelementptr inbounds %struct.FooContainer, %struct.FooContainer*
%agg.result, i64 0, i32 0
  store i16 0, i16* %a, align 2
  %arrayinit.begin = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 0
  store i8 0, i8* %arrayinit.begin, align 2
  %arrayinit.element = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 1
  store i8 1, i8* %arrayinit.element, align 1
  %arrayinit.element2 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 2
  store i8 2, i8* %arrayinit.element2, align 2
  %arrayinit.element3 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 3
  store i8 3, i8* %arrayinit.element3, align 1
  %arrayinit.element4 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 4
  store i8 4, i8* %arrayinit.element4, align 2
  %arrayinit.element5 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 5
  store i8 5, i8* %arrayinit.element5, align 1
  %arrayinit.element6 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 6
  store i8 6, i8* %arrayinit.element6, align 2
  %arrayinit.element7 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 7
  store i8 7, i8* %arrayinit.element7, align 1
  %arrayinit.element8 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 8
  store i8 8, i8* %arrayinit.element8, align 2
  %arrayinit.element9 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 9
  store i8 9, i8* %arrayinit.element9, align 1
  %arrayinit.element10 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 10
  store i8 10, i8* %arrayinit.element10, align 2
  %arrayinit.element11 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 11
  store i8 11, i8* %arrayinit.element11, align 1
  %arrayinit.element12 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 12
  store i8 12, i8* %arrayinit.element12, align 2
  %arrayinit.element13 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 13
  store i8 13, i8* %arrayinit.element13, align 1
  %arrayinit.element14 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 14
  store i8 14, i8* %arrayinit.element14, align 2
  %arrayinit.element15 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 15
  store i8 15, i8* %arrayinit.element15, align 1
  %c = getelementptr inbounds %struct.FooContainer, %struct.FooContainer*
%agg.result, i64 0, i32 2
  store i16 7, i16* %c, align 2
  ret void
}

-- 
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/20170202/dc09b77a/attachment-0001.html>


More information about the llvm-bugs mailing list