From 95c4f320d55fabf04ba45685109691f182678c01 Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 10 May 2023 01:34:47 +0000 Subject: cmd/compile: add De Morgan's rewrite rule Adds rules that rewrites statements such as ~P&~Q as ~(P|Q) and ~P|~Q as ~(P&Q), removing an extraneous instruction. Change-Id: Icedb97df741680ddf9799df79df78657173aa500 GitHub-Last-Rev: f22e2350c95e9052e990b2351c3c2b0af810e381 GitHub-Pull-Request: golang/go#60018 Reviewed-on: https://go-review.googlesource.com/c/go/+/493175 Reviewed-by: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: Stefan M Reviewed-by: Keith Randall Run-TryBot: Cherry Mui Reviewed-by: Cherry Mui --- test/codegen/logic.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/codegen/logic.go') diff --git a/test/codegen/logic.go b/test/codegen/logic.go index 748c639d6b..ac33f91dad 100644 --- a/test/codegen/logic.go +++ b/test/codegen/logic.go @@ -25,3 +25,17 @@ func ornot(x, y int) int { z := x | ^y return z } + +// Verify that (OR (NOT x) (NOT y)) rewrites to (NOT (AND x y)) +func orDemorgans(x, y int) int { + // amd64:"AND",-"OR" + z := ^x | ^y + return z +} + +// Verify that (AND (NOT x) (NOT y)) rewrites to (NOT (OR x y)) +func andDemorgans(x, y int) int { + // amd64:"OR",-"AND" + z := ^x & ^y + return z +} -- cgit v1.3