Skip to content

Switch default destination not eliminated despite known value range #76085

Closed
@mattiase

Description

@mattiase

A fully populated switch with known value range (but no explicit default clause) will still generate a conditional jump to the default destination:

void canthappen(void);
int g(int);

int f(int x) {
  if (x >= 0 && x <= 3) {
    switch (x) {
    case 0: return g(2);
    case 1: return g(3);
    case 2: return g(4);
    case 3: return g(5);
    }
    canthappen();
  }
  return -23;
}

results in a never-taken conditional branch to code that calls canthappen.
llvm 18.0.0git (9f74e6e).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions