Skip to content

[SimplifyCFG] Fold switch to wrapping range check #157113

@nikic

Description

@nikic

https://alive2.llvm.org/ce/z/mr3yq_

define i32 @src(i8 range(i8 0, 6) %arg) {
  switch i8 %arg, label %else [
    i8 0, label %if
    i8 4, label %if
    i8 5, label %if
  ]

if:
  ret i32 0

else:
  ret i32 1
}

define i32 @tgt(i8 %arg) {
  %add = add i8 %arg, -1
  %cmp2 = icmp ult i8 %add, 3
  br i1 %cmp2, label %else, label %if

if:
  ret i32 0

else:
  ret i32 1
}

The known range here allows us to express the switch condition as a wrapping range check.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions