diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-06-03 18:18:34 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-06-03 18:18:34 +0000 | 
| commit | 6d97bb297c123377182a5d78b412be5c1d723e08 (patch) | |
| tree | 5e57003ce58361eb4909e2a22461b096529d726f /contrib/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp | |
| parent | 4224465e820a1a7232255d980e692720169776af (diff) | |
| parent | d288ef4c1788d3a951a7558c68312c2d320612b1 (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp')
| -rw-r--r-- | contrib/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp | 21 | 
1 files changed, 18 insertions, 3 deletions
diff --git a/contrib/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/contrib/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp index f13629a3185f..dfac068d1f69 100644 --- a/contrib/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp +++ b/contrib/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -35,9 +35,12 @@ struct FoldCandidate {    };    unsigned char UseOpNo;    MachineOperand::MachineOperandType Kind; +  bool Commuted; -  FoldCandidate(MachineInstr *MI, unsigned OpNo, MachineOperand *FoldOp) : -    UseMI(MI), OpToFold(nullptr), UseOpNo(OpNo), Kind(FoldOp->getType()) { +  FoldCandidate(MachineInstr *MI, unsigned OpNo, MachineOperand *FoldOp, +                bool Commuted_ = false) : +    UseMI(MI), OpToFold(nullptr), UseOpNo(OpNo), Kind(FoldOp->getType()), +    Commuted(Commuted_) {      if (FoldOp->isImm()) {        ImmToFold = FoldOp->getImm();      } else if (FoldOp->isFI()) { @@ -59,6 +62,10 @@ struct FoldCandidate {    bool isReg() const {      return Kind == MachineOperand::MO_Register;    } + +  bool isCommuted() const { +    return Commuted; +  }  };  class SIFoldOperands : public MachineFunctionPass { @@ -237,8 +244,13 @@ static bool tryAddToFoldList(SmallVectorImpl<FoldCandidate> &FoldList,          !TII->commuteInstruction(*MI, false, CommuteIdx0, CommuteIdx1))        return false; -    if (!TII->isOperandLegal(*MI, OpNo, OpToFold)) +    if (!TII->isOperandLegal(*MI, OpNo, OpToFold)) { +      TII->commuteInstruction(*MI, false, CommuteIdx0, CommuteIdx1);        return false; +    } + +    FoldList.push_back(FoldCandidate(MI, OpNo, OpToFold, true)); +    return true;    }    FoldList.push_back(FoldCandidate(MI, OpNo, OpToFold)); @@ -699,6 +711,9 @@ void SIFoldOperands::foldInstOperand(MachineInstr &MI,        DEBUG(dbgs() << "Folded source from " << MI << " into OpNo " <<              static_cast<int>(Fold.UseOpNo) << " of " << *Fold.UseMI << '\n');        tryFoldInst(TII, Fold.UseMI); +    } else if (Fold.isCommuted()) { +      // Restoring instruction's original operand order if fold has failed. +      TII->commuteInstruction(*Fold.UseMI, false);      }    }  }  | 
