Skip to content

[InstCombine] sub(X, umin(X, Y)) => usub_sat(X, Y) (where supported?) #164495

@krzysz00

Description

@krzysz00

Alive2 verification

This here pattern

define i8 @src(i8 noundef %x, i8 noundef %y) {
  %z = call i8 @llvm.umin.i8(i8 %x, i8 %y)
  %z2 = sub i8 %x, %z
  ret i8 %z2
}

define i8 @tgt(i8 noundef %x, i8 noundef %y) {
  %z = call i8 @llvm.usub.sat(i8 %x, i8 %y)
  ret i8 %z
}

shows up a bunch in code generate at least from IREE if not general MLIR projects (once reasoning was done, often MLIR side, to convert what used to be smins into umins).

I think this is a good candidate for an InstCombine, since it shrinks the IR and removes duplicate uses of %x. It also looks to me like most targets support usubsat so this is a safe transform in general.

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions