-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[X86] Handle BSF/BSR "zero-input pass through" behaviour #123623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b01975b
aad5d63
a2fb67b
4e56688
f5ac988
cf42716
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5220,42 +5220,43 @@ inline static bool isDefConvertible(const MachineInstr &MI, bool &NoSignFlag, | |
} | ||
|
||
/// Check whether the use can be converted to remove a comparison against zero. | ||
static X86::CondCode isUseDefConvertible(const MachineInstr &MI) { | ||
/// Returns the EFLAGS condition and the operand that we are comparing against zero. | ||
static std::pair<X86::CondCode, unsigned> isUseDefConvertible(const MachineInstr &MI) { | ||
switch (MI.getOpcode()) { | ||
default: | ||
return X86::COND_INVALID; | ||
return std::make_pair(X86::COND_INVALID, ~0U); | ||
CASE_ND(NEG8r) | ||
CASE_ND(NEG16r) | ||
CASE_ND(NEG32r) | ||
CASE_ND(NEG64r) | ||
return X86::COND_AE; | ||
return std::make_pair(X86::COND_AE, 1U); | ||
case X86::LZCNT16rr: | ||
case X86::LZCNT32rr: | ||
case X86::LZCNT64rr: | ||
return X86::COND_B; | ||
return std::make_pair(X86::COND_B, 1U); | ||
case X86::POPCNT16rr: | ||
case X86::POPCNT32rr: | ||
case X86::POPCNT64rr: | ||
return X86::COND_E; | ||
return std::make_pair(X86::COND_E, 1U); | ||
case X86::TZCNT16rr: | ||
case X86::TZCNT32rr: | ||
case X86::TZCNT64rr: | ||
return X86::COND_B; | ||
return std::make_pair(X86::COND_B, 1U); | ||
case X86::BSF16rr: | ||
case X86::BSF32rr: | ||
case X86::BSF64rr: | ||
case X86::BSR16rr: | ||
case X86::BSR32rr: | ||
case X86::BSR64rr: | ||
return X86::COND_E; | ||
return std::make_pair(X86::COND_E, 2U); | ||
case X86::BLSI32rr: | ||
case X86::BLSI64rr: | ||
return X86::COND_AE; | ||
return std::make_pair(X86::COND_AE, 1U); | ||
case X86::BLSR32rr: | ||
case X86::BLSR64rr: | ||
case X86::BLSMSK32rr: | ||
case X86::BLSMSK64rr: | ||
return X86::COND_B; | ||
return std::make_pair(X86::COND_B, 1U); | ||
// TODO: TBM instructions. | ||
} | ||
} | ||
|
@@ -5336,6 +5337,7 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, | |
bool ClearsOverflowFlag = false; | ||
bool ShouldUpdateCC = false; | ||
bool IsSwapped = false; | ||
unsigned OpNo = 0; | ||
X86::CondCode NewCC = X86::COND_INVALID; | ||
int64_t ImmDelta = 0; | ||
|
||
|
@@ -5391,9 +5393,9 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, | |
// ... // EFLAGS not changed | ||
// testl %eax, %eax // <-- can be removed | ||
if (IsCmpZero) { | ||
NewCC = isUseDefConvertible(Inst); | ||
if (NewCC != X86::COND_INVALID && Inst.getOperand(1).isReg() && | ||
Inst.getOperand(1).getReg() == SrcReg) { | ||
std::tie(NewCC, OpNo) = isUseDefConvertible(Inst); | ||
if (NewCC != X86::COND_INVALID && Inst.getOperand(OpNo).isReg() && | ||
Inst.getOperand(OpNo).getReg() == SrcReg) { | ||
Comment on lines
+5396
to
+5398
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't put PassThru in the last operand? We don't need to change it then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is at the MI level, and the passthrough/fallback operand is tied to the destination reg (like any x86 binop) - it'd be weird to have a commutation and I expect could lead to further problems. |
||
ShouldUpdateCC = true; | ||
MI = &Inst; | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a comment for the returned pair?