aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/ssa/_gen/LOONG64.rules2
-rw-r--r--src/cmd/compile/internal/ssa/rewrite.go4
-rw-r--r--src/cmd/compile/internal/ssa/rewriteLOONG64.go47
3 files changed, 49 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules
index 0f58cbcc11..ab280f8f79 100644
--- a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules
+++ b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules
@@ -119,7 +119,9 @@
// rotates
(RotateLeft8 <t> x (MOVVconst [c])) => (Or8 (Lsh8x64 <t> x (MOVVconst [c&7])) (Rsh8Ux64 <t> x (MOVVconst [-c&7])))
+(RotateLeft8 <t> x y) => (OR <t> (SLLV <t> x (ANDconst <typ.Int64> [7] y)) (SRLV <t> (ZeroExt8to64 x) (ANDconst <typ.Int64> [7] (NEGV <typ.Int64> y))))
(RotateLeft16 <t> x (MOVVconst [c])) => (Or16 (Lsh16x64 <t> x (MOVVconst [c&15])) (Rsh16Ux64 <t> x (MOVVconst [-c&15])))
+(RotateLeft16 <t> x y) => (ROTR <t> (OR <typ.UInt32> (ZeroExt16to32 x) (SLLVconst <t> (ZeroExt16to32 x) [16])) (NEGV <typ.Int64> y))
(RotateLeft32 x y) => (ROTR x (NEGV <y.Type> y))
(RotateLeft64 x y) => (ROTRV x (NEGV <y.Type> y))
diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go
index b95afd9f2d..c7d5dc7106 100644
--- a/src/cmd/compile/internal/ssa/rewrite.go
+++ b/src/cmd/compile/internal/ssa/rewrite.go
@@ -2255,9 +2255,9 @@ func canRotate(c *Config, bits int64) bool {
return false
}
switch c.arch {
- case "386", "amd64", "arm64", "riscv64":
+ case "386", "amd64", "arm64", "loong64", "riscv64":
return true
- case "arm", "s390x", "ppc64", "ppc64le", "wasm", "loong64":
+ case "arm", "s390x", "ppc64", "ppc64le", "wasm":
return bits >= 32
default:
return false
diff --git a/src/cmd/compile/internal/ssa/rewriteLOONG64.go b/src/cmd/compile/internal/ssa/rewriteLOONG64.go
index f4b1997e18..e17c305f4f 100644
--- a/src/cmd/compile/internal/ssa/rewriteLOONG64.go
+++ b/src/cmd/compile/internal/ssa/rewriteLOONG64.go
@@ -6102,7 +6102,26 @@ func rewriteValueLOONG64_OpRotateLeft16(v *Value) bool {
v.AddArg2(v0, v2)
return true
}
- return false
+ // match: (RotateLeft16 <t> x y)
+ // result: (ROTR <t> (OR <typ.UInt32> (ZeroExt16to32 x) (SLLVconst <t> (ZeroExt16to32 x) [16])) (NEGV <typ.Int64> y))
+ for {
+ t := v.Type
+ x := v_0
+ y := v_1
+ v.reset(OpLOONG64ROTR)
+ v.Type = t
+ v0 := b.NewValue0(v.Pos, OpLOONG64OR, typ.UInt32)
+ v1 := b.NewValue0(v.Pos, OpZeroExt16to32, typ.UInt32)
+ v1.AddArg(x)
+ v2 := b.NewValue0(v.Pos, OpLOONG64SLLVconst, t)
+ v2.AuxInt = int64ToAuxInt(16)
+ v2.AddArg(v1)
+ v0.AddArg2(v1, v2)
+ v3 := b.NewValue0(v.Pos, OpLOONG64NEGV, typ.Int64)
+ v3.AddArg(y)
+ v.AddArg2(v0, v3)
+ return true
+ }
}
func rewriteValueLOONG64_OpRotateLeft32(v *Value) bool {
v_1 := v.Args[1]
@@ -6162,7 +6181,31 @@ func rewriteValueLOONG64_OpRotateLeft8(v *Value) bool {
v.AddArg2(v0, v2)
return true
}
- return false
+ // match: (RotateLeft8 <t> x y)
+ // result: (OR <t> (SLLV <t> x (ANDconst <typ.Int64> [7] y)) (SRLV <t> (ZeroExt8to64 x) (ANDconst <typ.Int64> [7] (NEGV <typ.Int64> y))))
+ for {
+ t := v.Type
+ x := v_0
+ y := v_1
+ v.reset(OpLOONG64OR)
+ v.Type = t
+ v0 := b.NewValue0(v.Pos, OpLOONG64SLLV, t)
+ v1 := b.NewValue0(v.Pos, OpLOONG64ANDconst, typ.Int64)
+ v1.AuxInt = int64ToAuxInt(7)
+ v1.AddArg(y)
+ v0.AddArg2(x, v1)
+ v2 := b.NewValue0(v.Pos, OpLOONG64SRLV, t)
+ v3 := b.NewValue0(v.Pos, OpZeroExt8to64, typ.UInt64)
+ v3.AddArg(x)
+ v4 := b.NewValue0(v.Pos, OpLOONG64ANDconst, typ.Int64)
+ v4.AuxInt = int64ToAuxInt(7)
+ v5 := b.NewValue0(v.Pos, OpLOONG64NEGV, typ.Int64)
+ v5.AddArg(y)
+ v4.AddArg(v5)
+ v2.AddArg2(v3, v4)
+ v.AddArg2(v0, v2)
+ return true
+ }
}
func rewriteValueLOONG64_OpRsh16Ux16(v *Value) bool {
v_1 := v.Args[1]