7.1. Boolean

A boolean is either true or false. A boolean can be represented by an i1 in MLIR.

7.1.1. Declaration

A boolean value is declared with the keyword boolean. If the variable is not initialized explicitly, it is set to false (zero).

7.1.2. Literals

The following are the only two valid boolean literals:

  • true

  • false

7.1.3. Operations

The following operations are defined on boolean values. In all of the usage examples bool-expr means some boolean yielding expression.

Operation

Symbol

Usage

Associativity

parenthesis

()

(bool-expr)

N/A

negation

not

not bool-expr

right

logical or

or

bool-expr or bool-expr

left

logical xor

xor

bool-expr xor bool-expr

left

logical and

and

bool-expr and bool-expr

left

equals

==

bool-expr == bool-expr

left

not equals

!=

bool-expr != bool-expr

left

Unlike many languages the and and or operators do not short circuit evaluation. Therefore, both the left hand side and right hand side of an expression must always be evaluated.

This table specifies boolean operator precedence. Operators without lines between them have the same level of precedence.

Precedence

Operation

HIGHER

not

==

!=

and

LOWER

or

xor

7.1.4. Type Casting and Type Promotion

To see the types that boolean may be cast and/or promoted to, see the sections on Type Casting and Type Promotion respectively.