[LLVMbugs] [Bug 18737] New: Missed optimization is switch

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Feb 5 02:00:38 PST 2014


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

            Bug ID: 18737
           Summary: Missed optimization is switch
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: chfast at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 12012
  --> http://llvm.org/bugs/attachment.cgi?id=12012&action=edit
C++ source

Example code in C++:

enum class Enum {
    A, B, C, D, E
};

int enum2int(Enum e) {
    switch (e) {
    case Enum::A:   return 0;
    case Enum::B:   return 1;
    case Enum::C:   return 2;
    case Enum::D:   return 3;
    case Enum::E:   return 4;
    }
}

In this case clang and opt with option -O3 used jump tables as an optimization.

@switch.table3 = private unnamed_addr constant [5 x i32] [i32 0, i32 1, i32 2,
i32 3, i32 4]

; Function Attrs: nounwind
define i32 @"\01?enum2int@@YAHW4Enum@@@Z"(i32 %e) #0 {
entry:
  %0 = icmp ult i32 %e, 5
  br i1 %0, label %switch.lookup, label %sw.epilog

sw.epilog:                                        ; preds = %entry
  tail call void @llvm.trap()
  unreachable

switch.lookup:                                    ; preds = %entry
  %switch.gep = getelementptr inbounds [5 x i32]* @switch.table3, i32 0, i32 %e
  %switch.load = load i32* %switch.gep, align 4
  ret i32 %switch.load
}

I think it could be optimized further as the input value is the same as output
value. @switch.table3 looks a bit silly.

-- 
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/20140205/41381681/attachment.html>


More information about the llvm-bugs mailing list