From e1f9013a58e5ad6d90ae0eb13a943aafa765d6e7 Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Mon, 24 Feb 2025 23:08:46 +1100 Subject: [PATCH] test/codegen: add riscv64 codegen for arithmetic tests Codify the current riscv64 code generation for various subtract from constant and addition/subtraction tests. Change-Id: I54ad923280a0578a338bc4431fa5bdc0644c4729 Reviewed-on: https://go-review.googlesource.com/c/go/+/652316 Reviewed-by: Meng Zhuo Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Reviewed-by: Mark Ryan Reviewed-by: David Chase --- test/codegen/arithmetic.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index f09af769f5..67bc88b587 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -85,36 +85,42 @@ func SubMem(arr []int, b, c, d int) int { func SubFromConst(a int) int { // ppc64x: `SUBC\tR[0-9]+,\s[$]40,\sR` + // riscv64: "ADDI\t\\$-40","NEG" b := 40 - a return b } func SubFromConstNeg(a int) int { // ppc64x: `ADD\t[$]40,\sR[0-9]+,\sR` + // riscv64: "NEG","ADDI\t\\$-40","NEG" c := 40 - (-a) return c } func SubSubFromConst(a int) int { // ppc64x: `ADD\t[$]20,\sR[0-9]+,\sR` + // riscv64: "ADDI\t\\$20",-"NEG" c := 40 - (20 - a) return c } func AddSubFromConst(a int) int { // ppc64x: `SUBC\tR[0-9]+,\s[$]60,\sR` + // riscv64: "ADDI\t\\$-60","NEG" c := 40 + (20 - a) return c } func NegSubFromConst(a int) int { // ppc64x: `ADD\t[$]-20,\sR[0-9]+,\sR` + // riscv64: "ADDI\t\\$-20" c := -(20 - a) return c } func NegAddFromConstNeg(a int) int { // ppc64x: `SUBC\tR[0-9]+,\s[$]40,\sR` + // riscv64: "ADDI\t\\$-40","NEG" c := -(-40 + a) return c } @@ -122,6 +128,7 @@ func NegAddFromConstNeg(a int) int { func SubSubNegSimplify(a, b int) int { // amd64:"NEGQ" // ppc64x:"NEG" + // riscv64:"NEG",-"SUB" r := (a - b) - a return r } @@ -129,6 +136,7 @@ func SubSubNegSimplify(a, b int) int { func SubAddSimplify(a, b int) int { // amd64:-"SUBQ",-"ADDQ" // ppc64x:-"SUB",-"ADD" + // riscv64:-"SUB",-"ADD" r := a + (b - a) return r } @@ -152,6 +160,7 @@ func SubAddSimplify2(a, b, c int) (int, int, int, int, int, int) { func SubAddNegSimplify(a, b int) int { // amd64:"NEGQ",-"ADDQ",-"SUBQ" // ppc64x:"NEG",-"ADD",-"SUB" + // riscv64:"NEG",-"ADD",-"SUB" r := a - (b + a) return r } @@ -159,6 +168,7 @@ func SubAddNegSimplify(a, b int) int { func AddAddSubSimplify(a, b, c int) int { // amd64:-"SUBQ" // ppc64x:-"SUB" + // riscv64:"ADD","ADD",-"SUB" r := a + (b + (c - a)) return r }