diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2014-11-06 23:23:30 +0000 | 
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2014-11-06 23:23:30 +0000 | 
| commit | c1eca5ad7c6a37c6b696bf129d5185e73c7a2e94 (patch) | |
| tree | cf72fb3e80c6180e1dd71d2dadfd9cf1369ecd8e /llvm/lib | |
| parent | 89cb4077295bf8a475fae7cd9e8af2f0765216f7 (diff) | |
| download | bcm5719-llvm-c1eca5ad7c6a37c6b696bf129d5185e73c7a2e94.tar.gz bcm5719-llvm-c1eca5ad7c6a37c6b696bf129d5185e73c7a2e94.zip  | |
InstCombine: Rely on cmpxchg's return code when it's strong
Comparing the result of a cmpxchg instruction can be replaced with an
extractvalue of the cmpxchg success indicator.
llvm-svn: 221498
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 16 | 
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index f7eb16cbb96..399f1c31755 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3418,6 +3418,22 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {      }    } +  // The 'cmpxchg' instruction returns an aggregate containing the old value and +  // an i1 which indicates whether or not we successfully did the swap. +  // +  // Replace comparisons between the old value and the expected value with the +  // indicator that 'cmpxchg' returns. +  // +  // N.B.  This transform is only valid when the 'cmpxchg' is not permitted to +  // spuriously fail.  In those cases, the old value may equal the expected +  // value but it is possible for the swap to not occur. +  if (I.getPredicate() == ICmpInst::ICMP_EQ) +    if (auto *EVI = dyn_cast<ExtractValueInst>(Op0)) +      if (auto *ACXI = dyn_cast<AtomicCmpXchgInst>(EVI->getAggregateOperand())) +        if (EVI->getIndices()[0] == 0 && ACXI->getCompareOperand() == Op1 && +            !ACXI->isWeak()) +          return ExtractValueInst::Create(ACXI, 1); +    {      Value *X; ConstantInt *Cst;      // icmp X+Cst, X  | 

