Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52011,22 +52011,32 @@ static SDValue combineOr(SDNode *N, SelectionDAG &DAG,
if (SDValue R = combineLogicBlendIntoPBLENDV(N, dl, DAG, Subtarget))
return R;

// (0 - SetCC) | C -> (zext (not SetCC)) * (C + 1) - 1 if we can get a LEA out of it.
if ((VT == MVT::i32 || VT == MVT::i64) &&
N0.getOpcode() == ISD::SUB && N0.hasOneUse() &&
isNullConstant(N0.getOperand(0))) {
SDValue Cond = N0.getOperand(1);
if (Cond.getOpcode() == ISD::ZERO_EXTEND && Cond.hasOneUse())
Cond = Cond.getOperand(0);

if (Cond.getOpcode() == X86ISD::SETCC && Cond.hasOneUse()) {
if (auto *CN = dyn_cast<ConstantSDNode>(N1)) {
uint64_t Val = CN->getZExtValue();
if (Val == 1 || Val == 2 || Val == 3 || Val == 4 || Val == 7 || Val == 8) {
X86::CondCode CCode = (X86::CondCode)Cond.getConstantOperandVal(0);
CCode = X86::GetOppositeBranchCondition(CCode);
SDValue NotCond = getSETCC(CCode, Cond.getOperand(1), SDLoc(Cond), DAG);
// Combine `(x86isd::setcc_carry) | C` and `(0 - SetCC) | C`
// into `(zext (not SetCC)) * (C + 1) - 1` if we can get a LEA out of it.
if ((VT == MVT::i32 || VT == MVT::i64) && N0.hasOneUse()) {
if (auto *CN = dyn_cast<ConstantSDNode>(N1)) {
uint64_t Val = CN->getZExtValue();
if (Val == 1 || Val == 2 || Val == 3 || Val == 4 || Val == 7 ||
Val == 8) {
SDValue NotCond;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this can be moved to line 520196.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I meant move N0.hasOneUse() to line 52016..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed that, updating again.

if (N0.getOpcode() == X86ISD::SETCC_CARRY &&
N0.getOperand(1).hasOneUse()) {
X86::CondCode OldCC = (X86::CondCode)N0.getConstantOperandVal(0);
X86::CondCode NewCC = X86::GetOppositeBranchCondition(OldCC);
NotCond = getSETCC(NewCC, N0.getOperand(1), SDLoc(N0), DAG);
} else if (N0.getOpcode() == ISD::SUB &&
isNullConstant(N0.getOperand(0))) {
SDValue Cond = N0.getOperand(1);
if (Cond.getOpcode() == ISD::ZERO_EXTEND && Cond.hasOneUse())
Cond = Cond.getOperand(0);
if (Cond.getOpcode() == X86ISD::SETCC && Cond.hasOneUse()) {
X86::CondCode OldCC = (X86::CondCode)Cond.getConstantOperandVal(0);
X86::CondCode NewCC = X86::GetOppositeBranchCondition(OldCC);
NotCond = getSETCC(NewCC, Cond.getOperand(1), SDLoc(Cond), DAG);
}
}

if (NotCond) {
SDValue R = DAG.getZExtOrTrunc(NotCond, dl, VT);
R = DAG.getNode(ISD::MUL, dl, VT, R, DAG.getConstant(Val + 1, dl, VT));
R = DAG.getNode(ISD::SUB, dl, VT, R, DAG.getConstant(1, dl, VT));
Expand Down
49 changes: 23 additions & 26 deletions llvm/test/CodeGen/X86/memcmp-more-load-pairs-x32.ll
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ define i32 @length3(ptr %X, ptr %Y) nounwind {
; X86-NEXT: popl %esi
; X86-NEXT: retl
; X86-NEXT: .LBB9_3: # %res_block
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpw %si, %dx
; X86-NEXT: sbbl %eax, %eax
; X86-NEXT: orl $1, %eax
; X86-NEXT: setae %al
; X86-NEXT: movzbl %al, %eax
; X86-NEXT: leal -1(%eax,%eax), %eax
; X86-NEXT: popl %esi
; X86-NEXT: retl
%m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 3) nounwind
Expand Down Expand Up @@ -284,10 +283,9 @@ define i32 @length5(ptr %X, ptr %Y) nounwind {
; X86-NEXT: popl %esi
; X86-NEXT: retl
; X86-NEXT: .LBB16_3: # %res_block
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpl %esi, %edx
; X86-NEXT: sbbl %eax, %eax
; X86-NEXT: orl $1, %eax
; X86-NEXT: setae %al
; X86-NEXT: movzbl %al, %eax
; X86-NEXT: leal -1(%eax,%eax), %eax
; X86-NEXT: popl %esi
; X86-NEXT: retl
%m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 5) nounwind
Expand Down Expand Up @@ -330,10 +328,9 @@ define i1 @length5_lt(ptr %X, ptr %Y) nounwind {
; X86-NEXT: subl %ecx, %eax
; X86-NEXT: jmp .LBB18_2
; X86-NEXT: .LBB18_3: # %res_block
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpl %esi, %edx
; X86-NEXT: sbbl %eax, %eax
; X86-NEXT: orl $1, %eax
; X86-NEXT: setae %al
; X86-NEXT: movzbl %al, %eax
; X86-NEXT: leal -1(%eax,%eax), %eax
; X86-NEXT: .LBB18_2: # %endblock
; X86-NEXT: shrl $31, %eax
; X86-NEXT: # kill: def $al killed $al killed $eax
Expand Down Expand Up @@ -367,8 +364,8 @@ define i32 @length7(ptr %X, ptr %Y) nounwind {
; X86-NEXT: .LBB19_2: # %res_block
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpl %edx, %ecx
; X86-NEXT: sbbl %eax, %eax
; X86-NEXT: orl $1, %eax
; X86-NEXT: setae %al
; X86-NEXT: leal -1(%eax,%eax), %eax
; X86-NEXT: .LBB19_3: # %endblock
; X86-NEXT: popl %esi
; X86-NEXT: retl
Expand Down Expand Up @@ -416,8 +413,8 @@ define i1 @length7_lt(ptr %X, ptr %Y) nounwind {
; X86-NEXT: .LBB21_2: # %res_block
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpl %edx, %ecx
; X86-NEXT: sbbl %eax, %eax
; X86-NEXT: orl $1, %eax
; X86-NEXT: setae %al
; X86-NEXT: leal -1(%eax,%eax), %eax
; X86-NEXT: .LBB21_3: # %endblock
; X86-NEXT: shrl $31, %eax
; X86-NEXT: # kill: def $al killed $al killed $eax
Expand Down Expand Up @@ -451,8 +448,8 @@ define i32 @length8(ptr %X, ptr %Y) nounwind {
; X86-NEXT: .LBB22_2: # %res_block
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpl %edx, %ecx
; X86-NEXT: sbbl %eax, %eax
; X86-NEXT: orl $1, %eax
; X86-NEXT: setae %al
; X86-NEXT: leal -1(%eax,%eax), %eax
; X86-NEXT: .LBB22_3: # %endblock
; X86-NEXT: popl %esi
; X86-NEXT: retl
Expand Down Expand Up @@ -613,8 +610,8 @@ define i32 @length12(ptr %X, ptr %Y) nounwind {
; X86-NEXT: .LBB29_3: # %res_block
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpl %edx, %ecx
; X86-NEXT: sbbl %eax, %eax
; X86-NEXT: orl $1, %eax
; X86-NEXT: setae %al
; X86-NEXT: leal -1(%eax,%eax), %eax
; X86-NEXT: .LBB29_4: # %endblock
; X86-NEXT: popl %esi
; X86-NEXT: retl
Expand Down Expand Up @@ -738,8 +735,8 @@ define i32 @length16(ptr %X, ptr %Y) nounwind {
; X86-NEXT: .LBB33_4: # %res_block
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpl %edx, %ecx
; X86-NEXT: sbbl %eax, %eax
; X86-NEXT: orl $1, %eax
; X86-NEXT: setae %al
; X86-NEXT: leal -1(%eax,%eax), %eax
; X86-NEXT: .LBB33_5: # %endblock
; X86-NEXT: popl %esi
; X86-NEXT: retl
Expand Down Expand Up @@ -852,8 +849,8 @@ define i1 @length16_lt(ptr %x, ptr %y) nounwind {
; X86-NEXT: .LBB35_4: # %res_block
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpl %edx, %ecx
; X86-NEXT: sbbl %eax, %eax
; X86-NEXT: orl $1, %eax
; X86-NEXT: setae %al
; X86-NEXT: leal -1(%eax,%eax), %eax
; X86-NEXT: .LBB35_5: # %endblock
; X86-NEXT: shrl $31, %eax
; X86-NEXT: # kill: def $al killed $al killed $eax
Expand Down Expand Up @@ -901,8 +898,8 @@ define i1 @length16_gt(ptr %x, ptr %y) nounwind {
; X86-NEXT: .LBB36_4: # %res_block
; X86-NEXT: xorl %edx, %edx
; X86-NEXT: cmpl %ecx, %eax
; X86-NEXT: sbbl %edx, %edx
; X86-NEXT: orl $1, %edx
; X86-NEXT: setae %dl
; X86-NEXT: leal -1(%edx,%edx), %edx
; X86-NEXT: .LBB36_5: # %endblock
; X86-NEXT: testl %edx, %edx
; X86-NEXT: setg %al
Expand Down
Loading