Thanks for your advice! I will fix it in patch v2.
在 2023/11/18 下午5:09, Xi Ruoyao 写道:
On Sat, 2023-11-18 at 14:59 +0800, Guo Jie wrote:
For the following immediate load operation in
gcc/testsuite/gcc.target/loongarch/imm-load1.c:
long long r = 0x0101010101010101;
Before this patch:
lu12i.w $r15,16842752>>12
ori $r15,$r15,257
lu32i.d $r15,0x1010100000000>>32
lu52i.d $r15,$r15,0x100000000000000>>52
After this patch:
lu12i.w $r15,16842752>>12
ori $r15,$r15,257
bstrins.d $r15,$r15,63,32
gcc/ChangeLog:
* config/loongarch/loongarch.cc (enum loongarch_load_imm_method): Add
new method.
(loongarch_build_integer): Add relevant implementations for new method.
(loongarch_move_integer): Ditto.
IIRC the ChangeLog line should be wrapped at 72 characters.
/* snip */
struct loongarch_integer_op
@@ -1556,11 +1560,23 @@ loongarch_build_integer (struct loongarch_integer_op
*codes,
int sign31 = (value & (HOST_WIDE_INT_1U << 31)) >> 31;
int sign51 = (value & (HOST_WIDE_INT_1U << 51)) >> 51;
+
+ unsigned HOST_WIDE_INT hival = value >> 32;
+ unsigned HOST_WIDE_INT loval = value << 32 >> 32;
Use
uint32_t hival = (uint32_t) (value >> 32);
uint32_t loval = (uint32_t) value;
instead, because "value << 32" may trigger a left-shift of negative
value.
C++11 doesn't allow shifting left any negative value. Yes it's allowed
as a GCC extension and it's also allowed by C++23, but GCC codebase is
still C++11. So it may break GCC if bootstrapping from a different
compiler, and --with-build-config=bootstrap-ubsan will complain.
Otherwise LGTM.