[RISCV] Fix a bug in i32 FP_TO_UINT_SAT lowering on RV64.
authorCraig Topper <craig.topper@sifive.com>
Tue, 13 Sep 2022 15:41:32 +0000 (08:41 -0700)
committerCraig Topper <craig.topper@sifive.com>
Tue, 13 Sep 2022 15:41:32 +0000 (08:41 -0700)
commit5224bae6130722dd41561422df1133eab60eb969
treed1921a1f66f8123cd1c4f8c76868a6da9754cd37
parent845dc178c0bb36af76229f89da7e13e866b010cd
[RISCV] Fix a bug in i32 FP_TO_UINT_SAT lowering on RV64.

We use the saturating behavior of fcvt.wu.h/s/d but forgot to
take into account that fcvt.wu will sign extend the saturated
result. According to computeKnownBits a promoted FP_TO_UINT_SAT
is expected to zero extend the saturated value.

In many case the upper bits aren't be demanded so this wouldn't
be an issue. But if we computeKnownBits caused an AND to be removed
it would be a bug.

This patch inserts an AND during to zero the upper bits.

Unfortunately, this pessimizes code if we aren't able to tell if
the upper bits are demanded. To fix that we could custom type
promote the FP_TO_UINT_SAT with SEXT_INREG after it, but I'll
leave that for future work.

I haven't found a failure from this, I was revisiting the code to
add vector support and spotted it.

Differential Revision: https://reviews.llvm.org/D133746
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/double-convert.ll
llvm/test/CodeGen/RISCV/float-convert.ll
llvm/test/CodeGen/RISCV/half-convert.ll