]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Remove side effects of vsetvl pattern in RTL.
authorJu-Zhe Zhong <juzhe.zhong@rivai.ai>
Tue, 20 Dec 2022 14:56:49 +0000 (22:56 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Fri, 23 Dec 2022 05:41:23 +0000 (13:41 +0800)
gcc/ChangeLog:

* config/riscv/riscv-vector-builtins-bases.cc: Change it to no side effects.
* config/riscv/vector.md (@vsetvl<mode>_no_side_effects): New pattern.

gcc/config/riscv/riscv-vector-builtins-bases.cc
gcc/config/riscv/vector.md

index 75879dea25a5f1f5137301dd7bcba71124d5a357..c1193dbbfb599f61be28f659b088d3572c2e3dbd 100644 (file)
@@ -75,7 +75,7 @@ public:
 
     /* MU.  */
     e.add_input_operand (Pmode, gen_int_mode (0, Pmode));
-    return e.generate_insn (code_for_vsetvl (Pmode));
+    return e.generate_insn (code_for_vsetvl_no_side_effects (Pmode));
   }
 };
 
index 52ca6b3d25cd79d8ccf7f7c564bd7cf48777284d..fd8e285a7e63db58c140d21f15a3c0d2d004898f 100644 (file)
   [(set_attr "type" "vsetvl")
    (set_attr "mode" "<MODE>")])
 
+;; It's emit by vsetvl/vsetvlmax intrinsics with no side effects.
+;; Since we have many optmization passes from "expand" to "reload_completed",
+;; such pattern can allow us gain benefits of these optimizations.
+(define_insn_and_split "@vsetvl<mode>_no_side_effects"
+  [(set (match_operand:P 0 "register_operand" "=r")
+       (unspec:P [(match_operand:P 1 "csr_operand" "rK")
+                  (match_operand 2 "const_int_operand" "i")
+                  (match_operand 3 "const_int_operand" "i")
+                  (match_operand 4 "const_int_operand" "i")
+                  (match_operand 5 "const_int_operand" "i")] UNSPEC_VSETVL))]
+  "TARGET_VECTOR"
+  "#"
+  "&& epilogue_completed"
+  [(parallel
+    [(set (match_dup 0)
+         (unspec:P [(match_dup 1) (match_dup 2) (match_dup 3)
+                    (match_dup 4) (match_dup 5)] UNSPEC_VSETVL))
+     (set (reg:SI VL_REGNUM)
+         (unspec:SI [(match_dup 1) (match_dup 2) (match_dup 3)] UNSPEC_VSETVL))
+     (set (reg:SI VTYPE_REGNUM)
+         (unspec:SI [(match_dup 2) (match_dup 3) (match_dup 4)
+                     (match_dup 5)] UNSPEC_VSETVL))])]
+  ""
+  [(set_attr "type" "vsetvl")
+   (set_attr "mode" "SI")])
+
 ;; RVV machine description matching format
 ;; (define_insn ""
 ;;   [(set (match_operand:MODE 0)