]> git.ipfire.org Git - thirdparty/gcc.git/commit
LoongArch: Fix uint64_t a & 0xfffffffffff on LA32
authormengqinggang <mengqinggang@loongson.cn>
Wed, 19 Nov 2025 06:19:39 +0000 (14:19 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Fri, 12 Dec 2025 07:56:47 +0000 (15:56 +0800)
commitbc3a77cdcdbecf8f21d64ec37ee097644ae46cb0
tree92673c89ac814a389cc83fbd98a0b20d245feee6
parenta79d9b6dbfb485055dd6cad2981dead4407d3b7d
LoongArch: Fix uint64_t a & 0xfffffffffff on LA32

"uint64_t a & 0xfffffffffff" expands to two and:SI on LA32 with -O0:

(insn 8 7 9 (set (subreg:SI (reg:DI 82 [ a_2 ]) 0)
         (and:SI (reg:SI 83)
             (const_int -1 [0xffffffffffffffff]))) "t.c":3:5 -1
      (nil))
(insn 10 9 11 (set (subreg:SI (reg:DI 82 [ a_2 ]) 4)
        (and:SI (reg:SI 84)
            (const_int 4095 [0xfff]))) "t.c":3:5 -1
     (nil))

"insn 8" -1 operand can't match Yx constraint low_bitmask_len condition.

low_bitmask_len can selects a field of low-order bits within an item but not
the entire word. Add (match_test "INTVAL (op) == -1") to low_bitmask_operand
predicate.

Note: "uint64_t a & 0xffffffffffffffff" and "uint32_t a & 0xffffffff" are
optimized away before expand with -O0, can't cause this error.

gcc/ChangeLog:

* config/loongarch/predicates.md: Add CONSTM1_RTX for low_bitmask_operand.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/la32/and.c: New test.
* gcc.target/loongarch/la32/la32.exp: New test.

Reviewed-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Lulu Cheng <chenglulu@loongson.cn>
gcc/config/loongarch/predicates.md
gcc/testsuite/gcc.target/loongarch/la32/and.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/la32/la32.exp [new file with mode: 0644]