[PATCH] D39383: [InstCombine] Simplify selects that test cmpxchg instructions

Matthew Simpson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 27 12:50:06 PDT 2017


mssimpso created this revision.

If a select instruction tests the returned flag of a cmpxchg instruction and selects between the returned value of the cmpxchg instruction and its compare operand, the result of the select will always be equal to its false value.

For example, in the code below `%2` is the original value located at `%ptr` prior to any potential update. If the cmpxchg operation succeeds (`%1` is true), `%2` and `%compare` must be equal. Thus, the result of the select is always equal to `%2`.

  %0 = cmpxchg i64* %ptr, i64 %compare, i64 %new_value seq_cst seq_cst
  %1 = extractvalue { i64, i1 } %0, 1
  %2 = extractvalue { i64, i1 } %0, 0
  %3 = select i1 %1, i64 %compare, i64 %2


https://reviews.llvm.org/D39383

Files:
  lib/Transforms/InstCombine/InstCombineSelect.cpp
  test/Transforms/InstCombine/select-cmpxchg.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39383.120678.patch
Type: text/x-patch
Size: 5664 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171027/5cda5c94/attachment.bin>


More information about the llvm-commits mailing list