Skip to content

Case gnu range need to be improved #632

Closed
@wenpen

Description

@wenpen

Pr #599 added support for gnu range in case statement, but the implementation need to store every integer inside the range.

For example, the following code will produce tons of repeated

  switch(x) {
    case 50 ... 233:
      return 1;
  }
switch i32 %5, label %8 [
    i32 50, label %6
    i32 51, label %6
    i32 52, label %6
    ...
    ...
    i32 231, label %6
    i32 232, label %6
    i32 233, label %6
  ], !dbg !12

While the OG codegen is smart

  switch i32 %0, label %sw.caserange [
  ]

sw.caserange:                                     ; preds = %entry
  %1 = sub i32 %0, 50
  %inbounds = icmp ule i32 %1, 183
  br i1 %inbounds, label %sw.bb, label %sw.epilog

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions