aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/BackendUtil.cpp
diff options
context:
space:
mode:
authorJorge Botto <Jorge.botto.16@ucl.ac.uk>2024-10-03 17:56:01 +0100
committerGitHub <noreply@github.com>2024-10-03 17:56:01 +0100
commita4516da49f8bda1b99d21dae7e1caba772d7182c (patch)
tree45a7c6141b6c801010449b19b95f737c81bc3f75 /clang/lib/CodeGen/BackendUtil.cpp
parentb0c9f023066e5ee9ca023dc0a94b30ed5e4f8362 (diff)
downloadllvm-a4516da49f8bda1b99d21dae7e1caba772d7182c.zip
llvm-a4516da49f8bda1b99d21dae7e1caba772d7182c.tar.gz
llvm-a4516da49f8bda1b99d21dae7e1caba772d7182c.tar.bz2
[AArch64] - Fold and and cmp into tst (#110347)
Fixes https://github.com/llvm/llvm-project/issues/102703. https://godbolt.org/z/nfj8xsb1Y The following pattern: ``` %2 = and i32 %0, 254 %3 = icmp eq i32 %2, 0 ``` is optimised by instcombine into: ```%3 = icmp ult i32 %0, 2``` However, post instcombine leads to worse aarch64 than the unoptimised version. Pre instcombine: ``` tst w0, #0xfe cset w0, eq ret ``` Post instcombine: ``` and w8, w0, #0xff cmp w8, #2 cset w0, lo ret ``` In the unoptimised version, SelectionDAG converts `SETCC (AND X 254) 0 EQ` into `CSEL 0 1 1 (ANDS X 254)`, which gets emitted as a `tst`. In the optimised version, SelectionDAG converts `SETCC (AND X 255) 2 ULT` into `CSEL 0 1 2 (SUBS (AND X 255) 2)`, which gets emitted as an `and`/`cmp`. This PR adds an optimisation to `AArch64ISelLowering`, converting `SETCC (AND X Y) Z ULT` into `SETCC (AND X (Y & ~(Z - 1))) 0 EQ` when `Z` is a power of two. This makes SelectionDAG/Codegen produce the same optimised code for both examples.
Diffstat (limited to 'clang/lib/CodeGen/BackendUtil.cpp')
0 files changed, 0 insertions, 0 deletions