[llvm] [InstCombine] Fold `sext(trunc nsw)` and `zext(trunc nuw)` (PR #88609)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 26 10:53:09 PDT 2024


andjo403 wrote:

noticed that the small number of changes in llvm-opt-benchmark is due to most cases is already handled in the https://github.com/llvm/llvm-project/blob/2c3d7d5322d3b3726c9984099ccdd21d29f6a740/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp#L1203-L1236 and 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp#L1494-L1513
so this fold is not executed.

the only cases that I can see will be handled by this fold when it is placed after the linked code is:
- when the src or target type is not defined in target Datalayout
- when the src or target type is a vector
- when there is multiple uses of the trunc instruction 

if the "target datalayout" in the test files is updated with "n8:16:32:64"  most of the test will no longer pass.

I tried and moved the fold before the code linked and got 3k files update in llvm-opt-benchmark.
see this commit https://github.com/llvm/llvm-project/compare/main...andjo403:llvm-project:truncNuwNswFold

https://github.com/llvm/llvm-project/pull/88609


More information about the llvm-commits mailing list