From dc6b7c86df3cac29c3506ef8b251345b8d914496 Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Wed, 12 Oct 2022 14:02:38 -0500 Subject: cmd/compile: merge zero constant ISEL in PPC64 lateLower pass Add a new SSA opcode ISELZ, similar to ISELB to represent a select of value or 0. Then, merge candidate ISEL opcodes inside the late lower pass. This avoids complicating rules within the the lower pass. Change-Id: I3b14c94b763863aadc834b0e910a85870c131313 Reviewed-on: https://go-review.googlesource.com/c/go/+/442596 TryBot-Result: Gopher Robot Reviewed-by: Lynn Boger Reviewed-by: Michael Knyszek Run-TryBot: Paul Murphy Reviewed-by: Joedian Reid --- test/codegen/condmove.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/codegen') diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go index bfab62213b..7b0f32e708 100644 --- a/test/codegen/condmove.go +++ b/test/codegen/condmove.go @@ -440,3 +440,27 @@ func cmovzero2(c bool) int { // loong64:"MASKNEZ", -"MASKEQZ" return x } + +// Conditionally selecting between a value or 0 can be done without +// an extra load of 0 to a register on PPC64 by using R0 (which always +// holds the value $0) instead. Verify both cases where either arg1 +// or arg2 is zero. +func cmovzeroreg0(a, b int) int { + x := 0 + if a == b { + x = a + } + // ppc64:"ISEL\t[$]2, R[0-9]+, R0, R[0-9]+" + // ppc64le:"ISEL\t[$]2, R[0-9]+, R0, R[0-9]+" + return x +} + +func cmovzeroreg1(a, b int) int { + x := a + if a == b { + x = 0 + } + // ppc64:"ISEL\t[$]2, R0, R[0-9]+, R[0-9]+" + // ppc64le:"ISEL\t[$]2, R0, R[0-9]+, R[0-9]+" + return x +} -- cgit v1.3