Skip to content

Missed Optimization: Fold parity select (x&1 ? (x-1): (x|1) ) into x ^ 1 #167173

@Leo0506

Description

@Leo0506
define i32 @src(i32 %arg0) {
  %v0 = and i32 %arg0, 1
  %v1 = icmp eq i32 %v0, 0
  %v2 = or disjoint i32 %arg0, 1
  %v3 = add nsw i32 %arg0, -1
  %v4 = select i1 %v1, i32 %v2, i32 %v3
  %v5 = srem i32 %v4, 6
  ret i32 %v5
}

define i32 @tgt(i32 %arg0) {
  %v4_opt = xor i32 %arg0, 1
  %v5_opt = srem i32 %v4_opt, 6
  ret i32 %v5_opt
}

alive2: https://alive2.llvm.org/ce/z/VGsqMZ
godbolt: https://godbolt.org/z/zETszvo4o
Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/linux/optimized/uncore_nhmex.ll

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions