Skip to content

Conversation

@mgehre-amd
Copy link
Collaborator

If we have a sequence of casts that first go to a bigger (f32) and then to a strictly smaller type (bf16), we can fold this and avoid the intermediate bigger type (f32).

@mgehre-amd mgehre-amd requested a review from jorickert December 10, 2024 23:53
@mgehre-amd mgehre-amd force-pushed the matthias.fold_cast_float branch from 8b20636 to ff2485b Compare December 11, 2024 00:11
@jorickert
Copy link

jorickert commented Dec 11, 2024

Are you sure that this folding is valid in all cases?
clang and gcc both compile a similar pattern also to different IR/assembly: https://godbolt.org/z/xcYs3M9Ya
I tried to validate the transformation with alive2, but it times out: https://alive2.llvm.org/ce/z/wpa2C2

@mgehre-amd
Copy link
Collaborator Author

Are you sure that this folding is valid in all cases? clang and gcc both compile a similar pattern also to different IR/assembly: godbolt.org/z/xcYs3M9Ya I tried to validate the transformation with alive2, but it times out: alive2.llvm.org/ce/z/wpa2C2

Hm, then let me restrict this to bf16 -> f32 -> bf16, which clang thinks is the same as noop: https://godbolt.org/z/a418qje9a

@mgehre-amd mgehre-amd enabled auto-merge December 11, 2024 10:26
@mgehre-amd mgehre-amd merged commit 8eff95a into feature/fused-ops Dec 11, 2024
4 checks passed
@mgehre-amd mgehre-amd deleted the matthias.fold_cast_float branch December 11, 2024 10:31
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