[llvm] [InstCombine] Allow simplifying FP selects of cmpxchg instructions. (PR #181977)
Ricardo Jesus via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 18 10:51:40 PST 2026
================
@@ -2765,6 +2765,16 @@ static Value *foldSelectCmpXchg(SelectInst &SI) {
// to I. If such conditions are true, the helper returns the cmpxchg
// instruction; otherwise, a nullptr is returned.
auto isExtractFromCmpXchg = [](Value *V, unsigned I) -> AtomicCmpXchgInst * {
+ // When extracting the value loaded by a cmpxchg, allow peeking through a
+ // bitcast. These are inserted for floating-point cmpxchg, for example:
+ // %bc = bitcast float %compare to i32
+ // %cmpxchg = cmpxchg ptr %ptr, i32 %bc, i32 %new_value seq_cst seq_cst
+ // %val = extractvalue { i32, i1 } %cmpxchg, 0
+ // %success = extractvalue { i32, i1 } %cmpxchg, 1
+ // %val.bc = bitcast i32 %val to float
+ // %sel = select i1 %success, float %compare, float %val.bc
+ if (I == 0 && isa<BitCastInst>(V))
+ V = cast<BitCastInst>(V)->getOperand(0);
----------------
rj-jesus wrote:
Thanks for the suggestions. :)
https://github.com/llvm/llvm-project/pull/181977
More information about the llvm-commits
mailing list