]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Make full use of load insns with unsigned extension
authorGuo Jie <guojie@loongson.cn>
Sun, 2 Nov 2025 03:32:07 +0000 (11:32 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Mon, 3 Nov 2025 08:10:45 +0000 (16:10 +0800)
gcc/ChangeLog:

* config/loongarch/loongarch.md
(and_load_zero_extend<mode>): New combiner.
* config/loongarch/predicates.md
(mask_operand): New predicate.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/mem-and-mask-opt.c: New test.

gcc/config/loongarch/loongarch.md
gcc/config/loongarch/predicates.md
gcc/testsuite/gcc.target/loongarch/mem-and-mask-opt.c [new file with mode: 0644]

index 9371134a69dbc25fd96c9a8058475f3440c66e76..c61abcea3eda11dc54214e74779c14d4ef33078d 100644 (file)
     operands[3] = tmp;
   })
 
+(define_insn "and_load_zero_extend<mode>"
+  [(set (match_operand:X 0 "register_operand" "=r,r,r,r,r,r")
+       (and:X (match_operand:X 1 "memory_operand" "%m,m,m,k,k,k")
+              (match_operand:X 2 "mask_operand" "Yb,Yh,Yw,Yb,Yh,Yw")))]
+  ""
+  "@
+   ld.bu\t%0,%1
+   ld.hu\t%0,%1
+   ld.wu\t%0,%1
+   ldx.bu\t%0,%1
+   ldx.hu\t%0,%1
+   ldx.wu\t%0,%1"
+  [(set_attr "move_type" "load,load,load,load,load,load")
+   (set_attr "mode" "<MODE>")])
+
 ;; We always avoid the shift operation in bstrins_<mode>_for_ior_mask
 ;; if possible, but the result may be sub-optimal when one of the masks
 ;; is (1 << N) - 1 and one of the src register is the dest register.
index 34cf74d5d66e26fd30e34db41734152118b170b3..8460618b501b9c9f3afe5d76e8597529d4c45911 100644 (file)
        (match_operand 0 "low_bitmask_operand")
        (match_operand 0 "ins_zero_bitmask_operand")))
 
+(define_predicate "mask_operand"
+  (ior (match_operand 0 "qi_mask_operand")
+       (match_operand 0 "hi_mask_operand")
+       (match_operand 0 "si_mask_operand")))
+
 (define_predicate "const_call_insn_operand"
   (match_code "const,symbol_ref,label_ref")
 {
diff --git a/gcc/testsuite/gcc.target/loongarch/mem-and-mask-opt.c b/gcc/testsuite/gcc.target/loongarch/mem-and-mask-opt.c
new file mode 100644 (file)
index 0000000..9b3a5cd
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+/* { dg-final { scan-assembler-not "bstrpick" } } */
+/* { dg-final { scan-assembler "ld\\.wu" } } */
+
+struct st
+{
+  char const *name;
+};
+struct fst
+{
+  struct st *groups;
+};
+
+struct fst *pfunc (int);
+
+const char *
+test (int pc, unsigned group)
+{
+  struct fst *pci = pfunc (pc);
+
+  return pci->groups[group].name;
+}