diff options
author | Rahul Yadav <rahul4talk@gmail.com> | 2025-07-21 17:14:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-21 17:14:56 +0100 |
commit | 04e5e643f526090ec872c0e505c487918992e21d (patch) | |
tree | a484658775bfdc16c6b4aac6cd329feaec3e120b /llvm/lib/Object/ObjectFile.cpp | |
parent | a270fdf3fe58dff7093c8bc1c7ffbd03c0268d66 (diff) | |
download | llvm-04e5e643f526090ec872c0e505c487918992e21d.zip llvm-04e5e643f526090ec872c0e505c487918992e21d.tar.gz llvm-04e5e643f526090ec872c0e505c487918992e21d.tar.bz2 |
[VectorCombine] Generalize foldBitOpOfBitcasts to support more cast operations (#148350)
This patch generalizes the existing foldBitOpOfBitcasts optimization in the VectorCombine pass to handle additional cast operations beyond just bitcast.
Fixes: [#146037](https://github.com/llvm/llvm-project/issues/146037)
Summary
The optimization now supports folding bitwise operations (AND/OR/XOR)
with the following cast operations:
- bitcast (original functionality)
- trunc (truncate)
- sext (sign extend)
- zext (zero extend)
The transformation pattern is:
bitop(castop(x), castop(y)) -> castop(bitop(x, y))
This reduces the number of cast instructions from 2 to 1, improving
performance on targets where cast operations
are expensive or where performing bitwise operations on narrower types
is beneficial.
Implementation Details
- Renamed foldBitOpOfBitcasts to foldBitOpOfCastops to reflect broader
functionality
- Extended pattern matching to handle any CastInst operation
- Added validation for each cast type's constraints (e.g., trunc
requires source > dest)
- Updated cost model to use the actual cast opcode
- Preserves IR flags from original instructions
- Handles multi-use scenarios appropriately
Testing
- Added comprehensive tests in
test/Transforms/VectorCombine/bitop-of-castops.ll
- Tests cover all supported cast types with all bitwise operations
- Includes negative tests for unsupported patterns
- All existing VectorCombine tests pass
Diffstat (limited to 'llvm/lib/Object/ObjectFile.cpp')
0 files changed, 0 insertions, 0 deletions