This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Simplify selects that test cmpxchg instructions
ClosedPublic

Authored by mssimpso on Oct 27 2017, 12:50 PM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

mssimpso created this revision.Oct 27 2017, 12:50 PM
This revision is now accepted and ready to land.Oct 30 2017, 10:59 AM
This revision was automatically updated to reflect the committed changes.