[llvm] [InstCombine] Add folds for `(fp_binop ({s|u}itofp x), ({s|u}itofp y))` (PR #82555)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 12:27:41 PDT 2024


goldsteinn wrote:

> > > This commit `946ea4e3ca4c908bfa7c196b982795f5c390b923` caused the following program to produce inconsistent results:
> > > ```c
> > > #include <stdio.h>
> > > static int g_12 = 0xD010L;
> > > static float g_842 = 1.0;
> > > static volatile int g_2345 = 1;
> > > 
> > > static float(safe_mul_func_float_f_f)(float sf1, float sf2) {
> > >   return (((0x1.0p-100f * sf1) * (0x1.0p-28f * sf2)) >
> > >           (0x1.0p-100f * (0x1.0p-28f * 3.40282347e+38F)))
> > >              ? (sf1)
> > >              : (sf1 * sf2);
> > > }
> > > 
> > > static void func_10(int p_11) {
> > >   g_842 = safe_mul_func_float_f_f(0.0, (short)p_11);
> > >   g_12 = 65529UL;
> > >   g_2345 = p_11;
> > > }
> > > 
> > > int main(int argc, char *argv[]) {
> > >   func_10(g_12);
> > >   printf("%f\n", g_842);
> > >   return 0;
> > > }
> > > ```
> > > 
> > > 
> > >     
> > >       
> > >     
> > > 
> > >       
> > >     
> > > 
> > >     
> > >   
> > > Before: `-0.000000` After: `0.000000`
> > > This is my compilation option:
> > > ```
> > > build/bin/clang --target=riscv64-unknown-elf -march=rv64gcv -mabi=lp64d src/foo-main.c --gcc-toolchain=${GCC_TOOLCHAIN} --sysroot=${GCC_TOOLCHAIN}/riscv64-unknown-elf -O3
> > > qemu-riscv64 a.out
> > > ```
> > > 
> > > 
> > >     
> > >       
> > >     
> > > 
> > >       
> > >     
> > > 
> > >     
> > >   
> > > `safe_mul_func_float_f_f` I removed the call to `fabsf` in order to eliminate the dependency on `math.h`.
> > 
> > 
> > Reproduce, I think the issue is we don't check constants are ~positive~ non-zero for `sitofp` + `fmul`. If thats the issue, ill have patch up shortly. Otherwise Ill revert. (A bit reluctant to revert as there are 3 patches that have to go with it, but if can't find fix shortly will do so).
> 
> Yeah adding a non-zero check for constant fixes. Will have patch up soon.

Fix is up at: https://github.com/llvm/llvm-project/pull/85298

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


More information about the llvm-commits mailing list