Skip to content

Commit b06245b

Browse files
committed
Move def to X86InstrInfo.h/cpp for sharing
1 parent f62a76e commit b06245b

File tree

3 files changed

+65
-62
lines changed

3 files changed

+65
-62
lines changed

llvm/lib/Target/X86/X86ConditionalCompares.cpp

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -548,67 +548,6 @@ bool SSACCmpConv::canConvert(MachineBasicBlock *MBB) {
548548
return true;
549549
}
550550

551-
static int getCondFlagsFromCondCode(X86::CondCode CC) {
552-
// CCMP/CTEST has two conditional operands:
553-
// - SCC: source conditonal code (same as CMOV)
554-
// - DCF: destination conditional flags, which has 4 valid bits
555-
//
556-
// +----+----+----+----+
557-
// | OF | SF | ZF | CF |
558-
// +----+----+----+----+
559-
//
560-
// If SCC(source conditional code) evaluates to false, CCMP/CTEST will updates
561-
// the conditional flags by as follows:
562-
//
563-
// OF = DCF.OF
564-
// SF = DCF.SF
565-
// ZF = DCF.ZF
566-
// CF = DCF.CF
567-
// PF = DCF.CF
568-
// AF = 0 (Auxiliary Carry Flag)
569-
//
570-
// Otherwise, the CMP or TEST is executed and it updates the
571-
// CSPAZO flags normally.
572-
//
573-
// NOTE:
574-
// If SCC = P, then SCC evaluates to true regardless of the CSPAZO value.
575-
// If SCC = NP, then SCC evaluates to false regardless of the CSPAZO value.
576-
enum { CF = 1, ZF = 2, SF = 4, OF = 8, PF = CF };
577-
int Flags = 0;
578-
switch (CC) {
579-
default:
580-
llvm_unreachable("Illegal condition code!");
581-
case X86::COND_NO:
582-
case X86::COND_NE:
583-
case X86::COND_GE:
584-
case X86::COND_G:
585-
case X86::COND_AE:
586-
case X86::COND_A:
587-
case X86::COND_NS:
588-
case X86::COND_NP:
589-
break;
590-
case X86::COND_O:
591-
Flags |= OF;
592-
break;
593-
case X86::COND_B:
594-
case X86::COND_BE:
595-
Flags |= CF;
596-
break;
597-
case X86::COND_E:
598-
case X86::COND_LE:
599-
Flags |= ZF;
600-
break;
601-
case X86::COND_S:
602-
case X86::COND_L:
603-
Flags |= SF;
604-
break;
605-
case X86::COND_P:
606-
Flags |= PF;
607-
break;
608-
}
609-
return Flags;
610-
}
611-
612551
void SSACCmpConv::convert(SmallVectorImpl<MachineBasicBlock *> &RemovedBlocks) {
613552
LLVM_DEBUG(dbgs() << "Merging " << printMBBReference(*CmpBB) << " into "
614553
<< printMBBReference(*Head) << ":\n"
@@ -727,7 +666,7 @@ void SSACCmpConv::convert(SmallVectorImpl<MachineBasicBlock *> &RemovedBlocks) {
727666
BuildMI(*Head, CmpMI, CmpMI->getDebugLoc(), MCID)
728667
.add(Op0)
729668
.add(Op1)
730-
.addImm(getCondFlagsFromCondCode(CmpBBTailCC))
669+
.addImm(X86::getCondFlagsFromCondCode(CmpBBTailCC))
731670
.addImm(HeadCmpBBCC);
732671
CmpMI->eraseFromParent();
733672
Head->updateTerminator(CmpBB->getNextNode());

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,67 @@ X86::CondCode X86::getCondFromCFCMov(const MachineInstr &MI) {
31573157
: X86::COND_INVALID;
31583158
}
31593159

3160+
int X86::getCondFlagsFromCondCode(X86::CondCode CC) {
3161+
// CCMP/CTEST has two conditional operands:
3162+
// - SCC: source conditonal code (same as CMOV)
3163+
// - DCF: destination conditional flags, which has 4 valid bits
3164+
//
3165+
// +----+----+----+----+
3166+
// | OF | SF | ZF | CF |
3167+
// +----+----+----+----+
3168+
//
3169+
// If SCC(source conditional code) evaluates to false, CCMP/CTEST will updates
3170+
// the conditional flags by as follows:
3171+
//
3172+
// OF = DCF.OF
3173+
// SF = DCF.SF
3174+
// ZF = DCF.ZF
3175+
// CF = DCF.CF
3176+
// PF = DCF.CF
3177+
// AF = 0 (Auxiliary Carry Flag)
3178+
//
3179+
// Otherwise, the CMP or TEST is executed and it updates the
3180+
// CSPAZO flags normally.
3181+
//
3182+
// NOTE:
3183+
// If SCC = P, then SCC evaluates to true regardless of the CSPAZO value.
3184+
// If SCC = NP, then SCC evaluates to false regardless of the CSPAZO value.
3185+
enum { CF = 1, ZF = 2, SF = 4, OF = 8, PF = CF };
3186+
int Flags = 0;
3187+
switch (CC) {
3188+
default:
3189+
llvm_unreachable("Illegal condition code!");
3190+
case X86::COND_NO:
3191+
case X86::COND_NE:
3192+
case X86::COND_GE:
3193+
case X86::COND_G:
3194+
case X86::COND_AE:
3195+
case X86::COND_A:
3196+
case X86::COND_NS:
3197+
case X86::COND_NP:
3198+
break;
3199+
case X86::COND_O:
3200+
Flags |= OF;
3201+
break;
3202+
case X86::COND_B:
3203+
case X86::COND_BE:
3204+
Flags |= CF;
3205+
break;
3206+
case X86::COND_E:
3207+
case X86::COND_LE:
3208+
Flags |= ZF;
3209+
break;
3210+
case X86::COND_S:
3211+
case X86::COND_L:
3212+
Flags |= SF;
3213+
break;
3214+
case X86::COND_P:
3215+
Flags |= PF;
3216+
break;
3217+
}
3218+
return Flags;
3219+
}
3220+
31603221
/// Return the inverse of the specified condition,
31613222
/// e.g. turning COND_E to COND_NE.
31623223
X86::CondCode X86::GetOppositeBranchCondition(X86::CondCode CC) {

llvm/lib/Target/X86/X86InstrInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ CondCode getCondFromCMov(const MachineInstr &MI);
7171
// Turn CFCMOV instruction into condition code.
7272
CondCode getCondFromCFCMov(const MachineInstr &MI);
7373

74+
// Turn condition code into condition flags for CCMP/CTEST.
75+
int getCondFlagsFromCondCode(CondCode CC);
76+
7477
/// GetOppositeBranchCondition - Return the inverse of the specified cond,
7578
/// e.g. turning COND_E to COND_NE.
7679
CondCode GetOppositeBranchCondition(CondCode CC);

0 commit comments

Comments
 (0)