Widening a G_FCONSTANT by extending and then generating G_FPTRUNC doesn't produce the same result all the time. Instead, we can just transform it to a G_CONSTANT of the same bit pattern and truncate using a plain G_TRUNC instead.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Widening a G_FCONSTANT by extending and then generating G_FPTRUNC doesn't produce the same result all the time.
That's only a problem if you care about the bit pattern of NaNs, right? It should be OK for all non-NaN values.
Yeah, but it seems better to handle this as a G_CONSTANT rather than have value dependent legalization.
Agreed, I wasn't suggesting to change anything, just trying to understand what the problem was.
I don't really understand why we have G_FCONSTANT in the first place. Also I don't really understand the concept of legalizing a constant.
It probably makes selection easier when importing patterns, so that's something that might cause some issues if we decide to remove it one day.
Could use some additional end to end tests, particularly ones that change the value (and some cases where it folds through an fpext to a legalized operation). We might be missing some constant fold code that bothers handling G_CONSTANT and G_FCONSTANT interchangeably.
I added a couple of tests but not exactly sure what you meant by "folds through fpext". I guess at the moment we don't have any constant folding that will transform G_FPEXT(G_CONSTANT) -> wide G_CONSTANT.