Skip to content

Conversation

@alister-chowdhury
Copy link
Contributor

ReassociateNestedGenericInt
Reassociate integer instructions where both operands share the same opcode and both source instructions contain a constant.
e.g:

  (a * C0) * (C1 * b) = (C0 * C1) * (a * b)
  (a ^ C0) ^ (b ^ C1) = (C0 ^ C1) ^ (a ^ b)
  (C0 | a) | (b | C1) = (C0 | C1) | (a | b)
  (a & C0) & (b & C1) = (C0 & C1) & (a & b)

ReassociateNestedMulDivFloat
Reassociate floating point mul/div instructions, which have mul/div inputs, both of which contain a constant.
e.g:

  (a * C0) / (C1 / b) =  (C0 / C1) * (a * b)
  (C0 / a) * (b / C1) =  (C0 / C1) * (b / a)
  (a / C0) / (b * C1) =  (1 / (C0 * C1)) * (a / b)

ReassociateNestedAddSub
Reassociate add/sub instructions, which have add/sub inputs, both of which contain a constant.
e.g:

  (a + C0) - (C1 - b) =  (C0 - C1) + (a + b)
  (C0 - a) + (b - C1) =  (C0 - C1) + (b - a)
  (a - C0) - (b + C1) = (-C0 - C1) + (a - b)

@s-perron s-perron requested review from luciechoi and s-perron and removed request for s-perron December 10, 2025 16:18
**ReassociateNestedGenericInt**
Reassociate integer instructions where both operands share the same opcode
and both source instructions contain a constant.
e.g:
```
  (a * C0) * (C1 * b) = (C0 * C1) * (a * b)
  (a ^ C0) ^ (b ^ C1) = (C0 ^ C1) ^ (a ^ b)
  (C0 | a) | (b | C1) = (C0 | C1) | (a | b)
  (a & C0) & (b & C1) = (C0 & C1) & (a & b)
```

**ReassociateNestedMulDivFloat**
Reassociate floating point mul/div instructions, which have mul/div inputs,
both of which contain a constant.
e.g:
```
  (a * C0) / (C1 / b) =  (C0 / C1) * (a * b)
  (C0 / a) * (b / C1) =  (C0 / C1) * (b / a)
  (a / C0) / (b * C1) =  (1 / (C0 * C1)) * (a / b)
```

**ReassociateNestedAddSub**
Reassociate add/sub instructions, which have add/sub inputs,
both of which contain a constant.
e.g:
```
  (a + C0) - (C1 - b) =  (C0 - C1) + (a + b)
  (C0 - a) + (b - C1) =  (C0 - C1) + (b - a)
  (a - C0) - (b + C1) = (-C0 - C1) + (a - b)
```
@alister-chowdhury
Copy link
Contributor Author

@luciechoi I'm not totally sure if the CI fails are related to my changes (but will happily fix them if they are).

CI-shaderc-smoketest

error: Operand '10[%10]' cannot be a type
  %13 = OpConstantSizeOfEXT %int %10

error: In Vulkan, untyped pointers can only be used in an explicitly laid out storage class
  %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant

error: TypeBufferEXT must appear in a block
  %36 = OpTypeBufferEXT StorageBuffer

CI-macos-clang-release-bazel

//:opt_fold_test                                                        TIMEOUT in 60.1s
  /private/var/tmp/_bazel_kbuilder/2111b75ca87ac686a1e657996f9442aa/execroot/_main/bazel-out/darwin_x86_64-fastbuild/testlogs/opt_fold_test/test.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants