Skip to content

Commit 1e5e666

Browse files
Michael Mundaygopherbot
authored andcommitted
cmd/compile: remove unnecessary casts and types from riscv64 rules
This change shouldn't have any impact on codegen. It removes some unnecessary int8 and int64 casts from the riscv64 rewrite rules. It also removes explicit typing where the types already match: `(OldOp <t>) => (NewOp <t>)` is the same as `(OldOp) => (NewOp)`. Change-Id: Ic02b65da8f548c8b9ad9ccb6627a03b7bf6f050f Reviewed-on: https://go-review.googlesource.com/c/go/+/719220 Reviewed-by: Junyang Shao <[email protected]> Auto-Submit: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Commit-Queue: Junyang Shao <[email protected]>
1 parent ddd8558 commit 1e5e666

File tree

2 files changed

+57
-68
lines changed

2 files changed

+57
-68
lines changed

src/cmd/compile/internal/ssa/_gen/RISCV64.rules

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -689,36 +689,36 @@
689689
(MOVDnop (MOVDconst [c])) => (MOVDconst [c])
690690

691691
// Avoid unnecessary zero and sign extension when right shifting.
692-
(SRAI <t> [x] (MOVWreg y)) && x >= 0 && x <= 31 => (SRAIW <t> [int64(x)] y)
693-
(SRLI <t> [x] (MOVWUreg y)) && x >= 0 && x <= 31 => (SRLIW <t> [int64(x)] y)
692+
(SRAI [x] (MOVWreg y)) && x >= 0 && x <= 31 => (SRAIW [x] y)
693+
(SRLI [x] (MOVWUreg y)) && x >= 0 && x <= 31 => (SRLIW [x] y)
694694

695695
// Replace right shifts that exceed size of signed type.
696696
(SRAI <t> [x] (MOVBreg y)) && x >= 8 => (SRAI [63] (SLLI <t> [56] y))
697697
(SRAI <t> [x] (MOVHreg y)) && x >= 16 => (SRAI [63] (SLLI <t> [48] y))
698-
(SRAI <t> [x] (MOVWreg y)) && x >= 32 => (SRAIW [31] y)
698+
(SRAI [x] (MOVWreg y)) && x >= 32 => (SRAIW [31] y)
699699

700700
// Eliminate right shifts that exceed size of unsigned type.
701-
(SRLI <t> [x] (MOVBUreg y)) && x >= 8 => (MOVDconst <t> [0])
702-
(SRLI <t> [x] (MOVHUreg y)) && x >= 16 => (MOVDconst <t> [0])
703-
(SRLI <t> [x] (MOVWUreg y)) && x >= 32 => (MOVDconst <t> [0])
701+
(SRLI [x] (MOVBUreg y)) && x >= 8 => (MOVDconst [0])
702+
(SRLI [x] (MOVHUreg y)) && x >= 16 => (MOVDconst [0])
703+
(SRLI [x] (MOVWUreg y)) && x >= 32 => (MOVDconst [0])
704704

705705
// Fold constant into immediate instructions where possible.
706706
(ADD (MOVDconst <t> [val]) x) && is32Bit(val) && !t.IsPtr() => (ADDI [val] x)
707707
(AND (MOVDconst [val]) x) && is32Bit(val) => (ANDI [val] x)
708708
(OR (MOVDconst [val]) x) && is32Bit(val) => (ORI [val] x)
709709
(XOR (MOVDconst [val]) x) && is32Bit(val) => (XORI [val] x)
710-
(ROL x (MOVDconst [val])) => (RORI [int64(int8(-val)&63)] x)
711-
(ROLW x (MOVDconst [val])) => (RORIW [int64(int8(-val)&31)] x)
712-
(ROR x (MOVDconst [val])) => (RORI [int64(val&63)] x)
713-
(RORW x (MOVDconst [val])) => (RORIW [int64(val&31)] x)
714-
(SLL x (MOVDconst [val])) => (SLLI [int64(val&63)] x)
715-
(SRL x (MOVDconst [val])) => (SRLI [int64(val&63)] x)
716-
(SLLW x (MOVDconst [val])) => (SLLIW [int64(val&31)] x)
717-
(SRLW x (MOVDconst [val])) => (SRLIW [int64(val&31)] x)
718-
(SRA x (MOVDconst [val])) => (SRAI [int64(val&63)] x)
719-
(SRAW x (MOVDconst [val])) => (SRAIW [int64(val&31)] x)
720-
(SLT x (MOVDconst [val])) && val >= -2048 && val <= 2047 => (SLTI [val] x)
721-
(SLTU x (MOVDconst [val])) && val >= -2048 && val <= 2047 => (SLTIU [val] x)
710+
(ROL x (MOVDconst [val])) => (RORI [-val&63] x)
711+
(ROLW x (MOVDconst [val])) => (RORIW [-val&31] x)
712+
(ROR x (MOVDconst [val])) => (RORI [val&63] x)
713+
(RORW x (MOVDconst [val])) => (RORIW [val&31] x)
714+
(SLL x (MOVDconst [val])) => (SLLI [val&63] x)
715+
(SLLW x (MOVDconst [val])) => (SLLIW [val&31] x)
716+
(SRL x (MOVDconst [val])) => (SRLI [val&63] x)
717+
(SRLW x (MOVDconst [val])) => (SRLIW [val&31] x)
718+
(SRA x (MOVDconst [val])) => (SRAI [val&63] x)
719+
(SRAW x (MOVDconst [val])) => (SRAIW [val&31] x)
720+
(SLT x (MOVDconst [val])) && is12Bit(val) => (SLTI [val] x)
721+
(SLTU x (MOVDconst [val])) && is12Bit(val) => (SLTIU [val] x)
722722

723723
// Replace negated left rotation with right rotation.
724724
(ROL x (NEG y)) => (ROR x y)
@@ -782,7 +782,7 @@
782782
(SRAI [x] (MOVDconst [y])) => (MOVDconst [int64(y) >> uint32(x)])
783783

784784
// Combine doubling via addition with shift.
785-
(SLLI <t> [c] (ADD x x)) && c < t.Size() * 8 - 1 => (SLLI <t> [c+1] x)
785+
(SLLI <t> [c] (ADD x x)) && c < t.Size() * 8 - 1 => (SLLI [c+1] x)
786786
(SLLI <t> [c] (ADD x x)) && c >= t.Size() * 8 - 1 => (MOVDconst [0])
787787

788788
// SLTI/SLTIU with constants.

0 commit comments

Comments
 (0)