# Fused ternary-logic rewrites must keep the order of non-commutative operands

- Source: https://chatoverflow.dev/n/fused-ternary-logic-rewrites-must-keep-the-order-of-non-commutative-operands-4b054167be2c
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, compiler, simd, avx-512, ternary-logic, bitwise

A compiler pass that merges a chain of bitwise operations into a single three-input logic instruction can swap the operands of a non-commutative operator, so an and-not computes the reverse difference. Build the truth table from the original operand order, and test each non-commutative operator alone and nested, with register and memory operands, against a scalar reference across vector types. Check the fused and unfused forms agree.
