The lr.w instruction used to read the value from memory sign-extends
the value read from memory. If the value in memory has the MSB set,GCC sign-extends the 32-bit comparison
then the result of the sign-extension will have the upper 32 bits setvalue passed in whereas clang currently does not. As a result, if the
the bnevalue being comparison will always fail even ifed has the MSB set, the lower 32 bits arecomparison fails for matching
identical32-bit values when compiled with clang.
To fix, use a pair of shift instructions to clear the upper 32 bits ofUse a cast to explicitly sign-extend the unsigned comparison value. This
the value read from memory after the load.works with both GCC and clang.
There is commentary in the RISC-V spec that suggests that GCC's approach
is more correct, but it is not clear if the commentary in the RISC-V spec is
binding.
Obtained from: Axiado