Skip to content

Unoptimal CFG optimization for simple select case with -O4 #2933

@MaxGraey

Description

@MaxGraey
function test(x: i32, y: i32, z: i32): i32 {
  return x ? y : z
}

which is equivalent to:

(func $test (param $p0 i32) (param $p1 i32) (param $p2 i32) (result i32)
  local.get $p0
  if $I0 (result i32)
    local.get $p1
  else
    local.get $p2
  end
)

Currently optimize with (only for -O4) to:

(func $test (param $p0 i32) (param $p1 i32) (param $p2 i32) (result i32)
  local.get $p0
  i32.eqz
  if $I0
    local.get $p2
    local.set $p1
  end
  local.get $p1
)

while optimal and expected output and this btw happening for (-O2 and -O3):

(func $test (param $p0 i32) (param $p1 i32) (param $p2 i32) (result i32)
  local.get $p1
  local.get $p2
  local.get $p0
  select
)

As I understand it relate to Relooper or Flatten pass?

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