Skip to content

Missed optimization: fold (x & C1) == C2 to x == C2 when C1 & C2 == C2 #154035

@zxt5

Description

@zxt5
define i1 @src(ptr %arg0) {
  %v0 = getelementptr inbounds nuw i8, ptr %arg0, i64 8
  %v1 = load i32, ptr %v0, align 8
  %v2 = and i32 %v1, 255
  %v3 = icmp eq i32 %v2, 17
  ret i1 %v3
}

define i1 @tgt(ptr %arg0) {
  %v0 = getelementptr inbounds i8, ptr %arg0, i64 8
  %v1 = load i8, ptr %v0, align 8
  %v2 = icmp eq i8 %v1, 17
  ret i1 %v2
}

Alive2: https://alive2.llvm.org/ce/z/tjnF6d
Godbolt: https://godbolt.org/z/9rrPhKE5b

Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/llvm/optimized/AArch64TargetMachine.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