@@ -3455,7 +3455,9 @@ inline static bool isRedundantFlagInstr(const MachineInstr &FlagI,
3455
3455
3456
3456
// / Check whether the definition can be converted
3457
3457
// / to remove a comparison against zero.
3458
- inline static bool isDefConvertible (const MachineInstr &MI) {
3458
+ inline static bool isDefConvertible (const MachineInstr &MI, bool &NoSignFlag) {
3459
+ NoSignFlag = false ;
3460
+
3459
3461
switch (MI.getOpcode ()) {
3460
3462
default : return false ;
3461
3463
@@ -3520,8 +3522,6 @@ inline static bool isDefConvertible(const MachineInstr &MI) {
3520
3522
case X86::SHL8r1: case X86::SHL16r1: case X86::SHL32r1:case X86::SHL64r1:
3521
3523
case X86::ANDN32rr: case X86::ANDN32rm:
3522
3524
case X86::ANDN64rr: case X86::ANDN64rm:
3523
- case X86::BEXTR32rr: case X86::BEXTR64rr:
3524
- case X86::BEXTR32rm: case X86::BEXTR64rm:
3525
3525
case X86::BLSI32rr: case X86::BLSI32rm:
3526
3526
case X86::BLSI64rr: case X86::BLSI64rm:
3527
3527
case X86::BLSMSK32rr:case X86::BLSMSK32rm:
@@ -3539,8 +3539,6 @@ inline static bool isDefConvertible(const MachineInstr &MI) {
3539
3539
case X86::TZCNT16rr: case X86::TZCNT16rm:
3540
3540
case X86::TZCNT32rr: case X86::TZCNT32rm:
3541
3541
case X86::TZCNT64rr: case X86::TZCNT64rm:
3542
- case X86::BEXTRI32ri: case X86::BEXTRI32mi:
3543
- case X86::BEXTRI64ri: case X86::BEXTRI64mi:
3544
3542
case X86::BLCFILL32rr: case X86::BLCFILL32rm:
3545
3543
case X86::BLCFILL64rr: case X86::BLCFILL64rm:
3546
3544
case X86::BLCI32rr: case X86::BLCI32rm:
@@ -3560,6 +3558,13 @@ inline static bool isDefConvertible(const MachineInstr &MI) {
3560
3558
case X86::TZMSK32rr: case X86::TZMSK32rm:
3561
3559
case X86::TZMSK64rr: case X86::TZMSK64rm:
3562
3560
return true ;
3561
+ case X86::BEXTR32rr: case X86::BEXTR64rr:
3562
+ case X86::BEXTR32rm: case X86::BEXTR64rm:
3563
+ case X86::BEXTRI32ri: case X86::BEXTRI32mi:
3564
+ case X86::BEXTRI64ri: case X86::BEXTRI64mi:
3565
+ // BEXTR doesn't update the sign flag so we can't use it.
3566
+ NoSignFlag = true ;
3567
+ return true ;
3563
3568
}
3564
3569
}
3565
3570
@@ -3662,8 +3667,9 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
3662
3667
// instruction we can eliminate the compare iff the use sets EFLAGS in the
3663
3668
// right way.
3664
3669
bool ShouldUpdateCC = false ;
3670
+ bool NoSignFlag = false ;
3665
3671
X86::CondCode NewCC = X86::COND_INVALID;
3666
- if (IsCmpZero && !isDefConvertible (*MI)) {
3672
+ if (IsCmpZero && !isDefConvertible (*MI, NoSignFlag )) {
3667
3673
// Scan forward from the use until we hit the use we're looking for or the
3668
3674
// compare instruction.
3669
3675
for (MachineBasicBlock::iterator J = MI;; ++J) {
@@ -3782,6 +3788,12 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
3782
3788
case X86::COND_O: case X86::COND_NO:
3783
3789
// CF and OF are used, we can't perform this optimization.
3784
3790
return false ;
3791
+ case X86::COND_S: case X86::COND_NS:
3792
+ // If SF is used, but the instruction doesn't update the SF, then we
3793
+ // can't do the optimization.
3794
+ if (NoSignFlag)
3795
+ return false ;
3796
+ break ;
3785
3797
}
3786
3798
3787
3799
// If we're updating the condition code check if we have to reverse the
0 commit comments