From 73d7635fae502f63a3774e1265f739bff8778113 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Mon, 27 Oct 2025 13:05:41 +0100 Subject: cmd/compile: add generic rules to remove bool → int → bool roundtrips MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8b0a3b64c89fe167d304f901a5d38470f35400ab Reviewed-on: https://go-review.googlesource.com/c/go/+/715200 LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Auto-Submit: Jorropo Reviewed-by: Michael Knyszek Reviewed-by: Keith Randall --- test/codegen/condmove.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/codegen') diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go index 97be0ced75..6d3a46b03c 100644 --- a/test/codegen/condmove.go +++ b/test/codegen/condmove.go @@ -507,3 +507,23 @@ func cmovmathhalveu(a uint, b bool) uint { // wasm:"I64ShrU", -"Select" return a } + +func branchlessBoolToUint8(b bool) (r uint8) { + if b { + r = 1 + } + return +} + +func cmovFromMulFromFlags64(x uint64, b bool) uint64 { + // amd64:-"MOVB.ZX" + r := uint64(branchlessBoolToUint8(b)) + // amd64:"CMOV",-"MOVB.ZX",-"MUL" + return x * r +} +func cmovFromMulFromFlags64sext(x int64, b bool) int64 { + // amd64:-"MOVB.ZX" + r := int64(int8(branchlessBoolToUint8(b))) + // amd64:"CMOV",-"MOVB.ZX",-"MUL" + return x * r +} -- cgit v1.3-6-g1900