[llvm] [InstCombine] Teach foldSelectOpOp about samesign (PR #122723)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 21 04:17:36 PST 2025


artagnon wrote:

> Hi @artagnon, is this change expected to change floating point evaluation precision? We've found a case where this leads to different results.

Seems a bit strange because the change did not touch FP compares. Could you kindly post an IR diff?

> A bit of an incomplete hint; I think the most interesting diff in IR before and after this change is: there are two missing `add`s before icmp
> 
> ```
> -  %111 = add nsw i32 %110, -131072
> -  %112 = icmp ult i32 %111, -262144
> -  %113 = select i1 %112, i32 0, i32 %110
> +  %111 = icmp ugt i32 %110, 131071
> +  %112 = select i1 %111, i32 0, i32 %110
> ```
> 
> and
> 
> ```
> -  %195 = ashr exact i32 %194, 13
> -  %196 = add nsw i32 %195, -131072
> -  %197 = icmp ult i32 %196, -262144
> ...
> +  %194 = ashr exact i32 %193, 13
> +  %195 = icmp ugt i32 %194, 131071
> ```

A strange diff, because the patch was only supposed to affect icmp samesign.

https://github.com/llvm/llvm-project/pull/122723


More information about the llvm-commits mailing list