diff options
| author | Stefan <Stefan.Mada@utah.edu> | 2023-05-10 01:34:47 +0000 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-05-10 16:32:25 +0000 |
| commit | 95c4f320d55fabf04ba45685109691f182678c01 (patch) | |
| tree | d3585e6118bacb6bef294ec37941d13209e7e8f1 /test/codegen/logic.go | |
| parent | f30cd520516037b2fdb367ddd8e0851019bf3440 (diff) | |
| download | go-95c4f320d55fabf04ba45685109691f182678c01.tar.xz | |
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 <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Stefan M <st3f4nm4d4@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'test/codegen/logic.go')
| -rw-r--r-- | test/codegen/logic.go | 14 |
1 files changed, 14 insertions, 0 deletions
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 +} |
