Skip to content

[InstCombine] Missed optimization for zext(trunc nuw(x)) #98017

Open
@Il-Capitano

Description

@Il-Capitano

Godbolt link: https://godbolt.org/z/Ws1jPz4rE

Instcombine transforms this function:

define i64 @test(i64 %n) {
    %trunc = trunc nuw i64 %n to i32
    %zext = zext i32 %trunc to i64
    ret i64 %zext
}

into this:

define i64 @test(i64 %n) {
  %zext = and i64 %n, 4294967295
  ret i64 %zext
}

However, because of the nuw flag on trunc, this could be simplified into this instead:

define i64 @test(i64 %n) {
    ret i64 %n
}

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