This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fix a bug in i32 FP_TO_UINT_SAT lowering on RV64.
ClosedPublic

Authored by craig.topper on Sep 12 2022, 8:52 PM.

Details

Summary

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.

Diff Detail

Event Timeline

craig.topper created this revision.Sep 12 2022, 8:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 12 2022, 8:52 PM
craig.topper requested review of this revision.Sep 12 2022, 8:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 12 2022, 8:52 PM
reames accepted this revision.Sep 13 2022, 7:53 AM

LGTM, good catch!

This revision is now accepted and ready to land.Sep 13 2022, 7:53 AM