-
Notifications
You must be signed in to change notification settings - Fork 664
spirv-fuzz: Transformation to adjust language operators #3440
Description
Overview
The idea behind this transformation is to introduce new instructions that don’t change the meaning of mathematical expressions. It can be illustrated as follows:
a => a + 0,
a => a * 1,
a => true && a
a => false || a
a > b => !(a <= b)
a == b => !(a != b)
3 => int(float(3))
etc…
Result of this transformation can later be used in other transformations to, for example, replace the constant (true, false, 0, 1) with a result of some expression that always evaluates to that constant.
Implementation
In fuzzer pass, we can simply iterate over all types and their usages in the module and for each usage randomly decide whether we want to add one of those instructions. For example, if we have an id of floating-point vector type, we can add an OpVectorTimesScalar instruction to multiply it by 1 or OpFAdd instruction to add a vector of zeros to it. These are type-dependent transformations. We also have instruction-dependent transformations (e.g. a > b => !(a <= b)). We might want to separate these into different transformations.