[RISCV] Avoid redundant branch-to-branch when expanding cmpxchg
authorAlex Bradbury <asb@igalia.com>
Wed, 17 Aug 2022 12:48:05 +0000 (13:48 +0100)
committerAlex Bradbury <asb@igalia.com>
Wed, 17 Aug 2022 12:49:15 +0000 (13:49 +0100)
commitce381281940fb6a9cc2fa1a16fa36bf0911f43f1
tree629cd00a8a18a5a1dc47b93054d3364bfc3388ad
parentcc8c746f8df5274ac20486bd62b1183c0583ea6a
[RISCV] Avoid redundant branch-to-branch when expanding cmpxchg

If the success value of a cmpxchg is used in a branch, the expanded
cmpxchg sequence ends up with a redundant branch-to-branch (as the
backend atomics expansion happens as late as possible, passes to
optimise such cases have already run). This patch identifies this case
and avoid it when expanding the cmpxchg.

Note that a similar optimisation is possible for a BEQ on the cmpxchg
success value. As it's hard to imagine a case where real-world code may
do that, this patch doens't handle that case.

Differential Revision: https://reviews.llvm.org/D130192
llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp
llvm/test/CodeGen/RISCV/atomic-cmpxchg-branch-on-result.ll