Daily bump.
[official-gcc.git] / gcc / config / riscv / peephole.md
blobe3948fb2e0c7fcc67df146507e0ad2c69276ff55
1 ;; Peephole optimizations for RISC-V for GNU compiler.
2 ;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
3 ;; Contributed by Andrew Waterman (andrew@sifive.com).
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
10 ;; any later version.
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
21 ;; Simplify (unsigned long)(unsigned int)a << const
22 (define_peephole2
23   [(set (match_operand:DI 0 "register_operand")
24         (ashift:DI (match_operand:DI 1 "register_operand")
25                    (match_operand 2 "const_int_operand")))
26    (set (match_operand:DI 3 "register_operand")
27         (lshiftrt:DI (match_dup 0) (match_dup 2)))
28    (set (match_operand:DI 4 "register_operand")
29         (ashift:DI (match_dup 3) (match_operand 5 "const_int_operand")))]
30   "TARGET_64BIT
31    && INTVAL (operands[5]) < INTVAL (operands[2])
32    && (REGNO (operands[3]) == REGNO (operands[4])
33        || peep2_reg_dead_p (3, operands[3]))"
34   [(set (match_dup 0)
35         (ashift:DI (match_dup 1) (match_dup 2)))
36    (set (match_dup 4)
37         (lshiftrt:DI (match_dup 0) (match_operand 5)))]
39   operands[5] = GEN_INT (INTVAL (operands[2]) - INTVAL (operands[5]));
42 ;; ZCMP
43 (define_peephole2
44   [(set (match_operand:X 0 "a0a1_reg_operand")
45         (match_operand:X 1 "zcmp_mv_sreg_operand"))
46    (set (match_operand:X 2 "a0a1_reg_operand")
47         (match_operand:X 3 "zcmp_mv_sreg_operand"))]
48   "TARGET_ZCMP
49    && (REGNO (operands[2]) != REGNO (operands[0]))"
50   [(parallel [(set (match_dup 0)
51                    (match_dup 1))
52               (set (match_dup 2)
53                    (match_dup 3))])]
56 (define_peephole2
57   [(set (match_operand:X 0 "zcmp_mv_sreg_operand")
58         (match_operand:X 1 "a0a1_reg_operand"))
59    (set (match_operand:X 2 "zcmp_mv_sreg_operand")
60         (match_operand:X 3 "a0a1_reg_operand"))]
61   "TARGET_ZCMP
62    && (REGNO (operands[0]) != REGNO (operands[2]))
63    && (REGNO (operands[1]) != REGNO (operands[3]))"
64   [(parallel [(set (match_dup 0)
65                    (match_dup 1))
66               (set (match_dup 2)
67                    (match_dup 3))])]