llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.32k stars 12.11k forks source link

[X86] Codegen for one of 'absolute difference' patterns is suboptimal #53045

Open LebedevRI opened 2 years ago

LebedevRI commented 2 years ago

As being pointed out in https://github.com/halide/Halide/pull/6545 we don't codegen a < b ? b - a : a - b as well as we do max(a, b) - min(a, b) https://godbolt.org/z/MvMj9MPW9 https://alive2.llvm.org/ce/z/pVHePi

The question is, what do we think is more canonical in IR?

llvmbot commented 2 years ago

@llvm/issue-subscribers-backend-X86

rotateright commented 2 years ago

Should we consider the form with min/max intrinsics? (we'll canonicalize to them some day...) https://alive2.llvm.org/ce/z/kCpnF8

We'll need backend optimizations no matter which form we choose in IR. Even within the scalar or vector subsets, x86 may be suboptimal depending on type (for example, no cmov for i8 directly).

RKSimon commented 2 years ago

CC @RKSimon

RKSimon commented 1 year ago

https://reviews.llvm.org/D144789 will add the select(icmp_gt(x,y),sub(x,y),sub(y,x)) -> abd(x,y) fold - although we don't support scalars