[llvm-bugs] [Bug 34285] New: Optimize switch over fields of homogeneous struct into pointer arithmetic

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 22 13:12:50 PDT 2017


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

            Bug ID: 34285
           Summary: Optimize switch over fields of homogeneous struct into
                    pointer arithmetic
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: arcata at gmail.com
                CC: llvm-bugs at lists.llvm.org

In the following IR, the switch arms could be optimized away into a dynamic gep
into the homogeneous struct, but this does not happen:

%equistruct = type { i32, i32, i32, i32 }

declare void @llvm.trap() noreturn nounwind

define void @index(%equistruct* %a, i32 %b, i32 %c) {
entry:
  switch i32 %b, label %default [
    i32 0, label %i0
    i32 1, label %i1
    i32 2, label %i2
    i32 3, label %i3
  ]

i0:
  %d0 = getelementptr %equistruct, %equistruct* %a, i32 0, i32 0
  store i32 %c, i32* %d0
  ret void

i1:
  %d1 = getelementptr %equistruct, %equistruct* %a, i32 0, i32 1
  store i32 %c, i32* %d1
  ret void

i2:
  %d2 = getelementptr %equistruct, %equistruct* %a, i32 0, i32 2
  store i32 %c, i32* %d2
  ret void

i3:
  %d3 = getelementptr %equistruct, %equistruct* %a, i32 0, i32 3
  store i32 %c, i32* %d3
  ret void

default:
  call void @llvm.trap()
  unreachable
}

-- 
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/20170822/62f7d43b/attachment.html>


More information about the llvm-bugs mailing list