"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, can't cause this error.
gcc/ChangeLog:
* config/loongarch/predicates.md: Add (match_test "INTVAL (op) == -1")
to low_bitmask_operand.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/and.c: New test.
---
gcc/config/loongarch/predicates.md | 4 +++-
gcc/testsuite/gcc.target/loongarch/and.c | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.target/loongarch/and.c
diff --git a/gcc/config/loongarch/predicates.md
b/gcc/config/loongarch/predicates.md
index 260e06bc695..fd4922c5e94 100644
--- a/gcc/config/loongarch/predicates.md
+++ b/gcc/config/loongarch/predicates.md
@@ -291,7 +291,9 @@ (define_predicate "si_mask_operand"
(define_predicate "low_bitmask_operand"
(and (match_code "const_int")
- (match_test "low_bitmask_len (mode, INTVAL (op)) > 12")
+ (ior
+ (match_test "low_bitmask_len (mode, INTVAL (op)) > 12")
+ (match_test "INTVAL (op) == -1"))
(match_test "!TARGET_32BIT_R")))
(define_predicate "d_operand"
diff --git a/gcc/testsuite/gcc.target/loongarch/and.c
b/gcc/testsuite/gcc.target/loongarch/and.c
new file mode 100644
index 00000000000..e990e7131a6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/and.c
@@ -0,0 +1,7 @@
+/* { dg-do compile { target { loongarch32*-*-* } } } */
+
+#include <stdint.h>
+uint64_t f(uint64_t a) {
+ a = a & 0xfffffffffffff;
+ return a;
+}
--
2.34.1