Follow-up to #106419 (discussion). When casting, for example, a ulong to a float, Roslyn emits the following IL:
Which is then imported by the JIT as a ulong -> float -> double cast sequence. Casting in two steps can produce slightly different results from casting directly to float, which is also why it isn't always correct to just morph the above IR into ulong -> float. Ideally, we would differentiate between ulong -> float and ulong -> double -> float during importation, and create IR that accurately models each pattern.
Similarly, constant folding should model each pattern correctly. In other words, to model ulong -> float, we should cast the constant directly to float, and rely on MSVC/Clang/GCC/etc. to emit the correct sequence.
cc @dotnet/jit-contrib
Follow-up to #106419 (discussion). When casting, for example, a
ulongto afloat, Roslyn emits the following IL:Which is then imported by the JIT as a
ulong -> float -> doublecast sequence. Casting in two steps can produce slightly different results from casting directly tofloat, which is also why it isn't always correct to just morph the above IR intoulong -> float. Ideally, we would differentiate betweenulong -> floatandulong -> double -> floatduring importation, and create IR that accurately models each pattern.Similarly, constant folding should model each pattern correctly. In other words, to model
ulong -> float, we should cast the constant directly tofloat, and rely on MSVC/Clang/GCC/etc. to emit the correct sequence.cc @dotnet/jit-contrib