diff --git a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules index a3dd050d14..d0a64364d6 100644 --- a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules +++ b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules @@ -730,6 +730,9 @@ (ADDV x0 x1:(SLLVconst [c] y)) && x1.Uses == 1 && c > 0 && c <= 4 => (ADDshiftLLV x0 y [c]) +// fold constant in ADDshift op +(ADDshiftLLV x (MOVVconst [c]) [d]) && is12Bit(c< (ADDVconst x [c< x (DIVVU x (MOVVconst [c])) && isPowerOfTwo(c) => (SRLVconst [log64(c)] x) diff --git a/src/cmd/compile/internal/ssa/rewriteLOONG64.go b/src/cmd/compile/internal/ssa/rewriteLOONG64.go index 036d70a15f..6a9b723c8c 100644 --- a/src/cmd/compile/internal/ssa/rewriteLOONG64.go +++ b/src/cmd/compile/internal/ssa/rewriteLOONG64.go @@ -324,6 +324,8 @@ func rewriteValueLOONG64(v *Value) bool { return rewriteValueLOONG64_OpLOONG64ADDV(v) case OpLOONG64ADDVconst: return rewriteValueLOONG64_OpLOONG64ADDVconst(v) + case OpLOONG64ADDshiftLLV: + return rewriteValueLOONG64_OpLOONG64ADDshiftLLV(v) case OpLOONG64AND: return rewriteValueLOONG64_OpLOONG64AND(v) case OpLOONG64ANDconst: @@ -2024,6 +2026,29 @@ func rewriteValueLOONG64_OpLOONG64ADDVconst(v *Value) bool { } return false } +func rewriteValueLOONG64_OpLOONG64ADDshiftLLV(v *Value) bool { + v_1 := v.Args[1] + v_0 := v.Args[0] + // match: (ADDshiftLLV x (MOVVconst [c]) [d]) + // cond: is12Bit(c<