[llvm] [InstCombine] Enable factorizeMinMaxTree for floating-point values (PR #193195)
Yunbo Ni via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 23 09:03:42 PDT 2026
cardigan1008 wrote:
Hi @thofry , here is a related miscomputation case:
```llvm
define <2 x float> @maximum_vec_common(<2 x float> %a, <2 x float> %b, <2 x float> %c) {
%m1 = call <2 x float> @llvm.maximum.v2f32(<2 x float> %a, <2 x float> %b)
%m2 = call nnan nsz <2 x float> @llvm.maximum.v2f32(<2 x float> %c, <2 x float> %a)
%r = call nnan <2 x float> @llvm.maximum.v2f32(<2 x float> %m1, <2 x float> %m2)
ret <2 x float> %r
}
```
is transformed into this with opt built on this patch:
```llvm
; ModuleID = 'src.ll'
source_filename = "src.ll"
define <2 x float> @maximum_vec_common(<2 x float> %a, <2 x float> %b, <2 x float> %c) {
%m2 = call nnan nsz <2 x float> @llvm.maximum.v2f32(<2 x float> %c, <2 x float> %a)
%r = call nnan <2 x float> @llvm.maximum.v2f32(<2 x float> %m2, <2 x float> %b)
ret <2 x float> %r
}
; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x float> @llvm.maximum.v2f32(<2 x float>, <2 x float>) #0
attributes #0 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
```
Alive2 proof:
```sh
$ alive-tv -passes=instcombine --disable-undef-input src.ll tgt.ll
----------------------------------------
define <2 x float> @maximum_vec_common(<2 x float> %a, <2 x float> %b, <2 x float> %c) {
#0:
%m1 = fmaximum <2 x float> %a, %b
%m2 = fmaximum nnan nsz <2 x float> %c, %a
%r = fmaximum nnan <2 x float> %m1, %m2
ret <2 x float> %r
}
=>
define <2 x float> @maximum_vec_common(<2 x float> %a, <2 x float> %b, <2 x float> %c) {
#0:
%m2 = fmaximum nnan nsz <2 x float> %c, %a
%r = fmaximum nnan <2 x float> %m2, %b
ret <2 x float> %r
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
<2 x float> %a = < #x7f802000 (SNaN), #x00000000 (+0.0) >
<2 x float> %b = < #x7f800200 (SNaN), #x82000002 (-0.000000000000?) >
<2 x float> %c = < #x00000000 (+0.0), #x00000000 (+0.0) >
Source:
<2 x float> %m1 = < #xffc00200 (QNaN), #x00000000 (+0.0) >
<2 x float> %m2 = < poison, #x00000000 (+0.0) >
<2 x float> %r = < poison, #x00000000 (+0.0) >
Target:
<2 x float> %m2 = < poison, #x80000000 (-0.0) >
<2 x float> %r = < poison, #x80000000 (-0.0) >
Source value: < poison, #x00000000 (+0.0) >
Target value: < poison, #x80000000 (-0.0) >
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```
For reference, the current version is: https://godbolt.org/z/b6dTTfYTs
> Found with [Archer](https://github.com/cuhk-s3/Archer). Please let me know if anything is wrong.
https://github.com/llvm/llvm-project/pull/193195
More information about the llvm-commits
mailing list