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.

7.1.2. Null

null is false for boolean.

7.1.3. Identity

identity is true for boolean.

7.1.4. Literals

The following are the only two valid boolean literals:

  • true

  • false

7.1.5. 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.6. 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.