mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 06:33:24 +00:00
(For X86) Enhancement to add-carray/sub-borrow (adc/sbb) optimization.
The adc/sbb optimization is to able to convert following expression into a single adc/sbb instruction: (ult) ... = x + 1 // where the ult is unsigned-less-than comparison (ult) ... = x - 1 This change is to flip the "x >u y" (i.e. ugt comparison) in order to expose the adc/sbb opportunity. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167180 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e57b2cbce6
commit
a5526a9bff
@ -16476,6 +16476,16 @@ static SDValue PerformISDSETCCCombine(SDNode *N, SelectionDAG &DAG) {
|
|||||||
return SDValue();
|
return SDValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function of PerformSETCCCombine. It is to materialize "setb reg"
|
||||||
|
// as "sbb reg,reg", since it can be extended without zext and produces
|
||||||
|
// an all-ones bit which is more useful than 0/1 in some cases.
|
||||||
|
static SDValue MaterializeSETB(DebugLoc DL, SDValue EFLAGS, SelectionDAG &DAG) {
|
||||||
|
return DAG.getNode(ISD::AND, DL, MVT::i8,
|
||||||
|
DAG.getNode(X86ISD::SETCC_CARRY, DL, MVT::i8,
|
||||||
|
DAG.getConstant(X86::COND_B, MVT::i8), EFLAGS),
|
||||||
|
DAG.getConstant(1, MVT::i8));
|
||||||
|
}
|
||||||
|
|
||||||
// Optimize RES = X86ISD::SETCC CONDCODE, EFLAG_INPUT
|
// Optimize RES = X86ISD::SETCC CONDCODE, EFLAG_INPUT
|
||||||
static SDValue PerformSETCCCombine(SDNode *N, SelectionDAG &DAG,
|
static SDValue PerformSETCCCombine(SDNode *N, SelectionDAG &DAG,
|
||||||
TargetLowering::DAGCombinerInfo &DCI,
|
TargetLowering::DAGCombinerInfo &DCI,
|
||||||
@ -16484,14 +16494,29 @@ static SDValue PerformSETCCCombine(SDNode *N, SelectionDAG &DAG,
|
|||||||
X86::CondCode CC = X86::CondCode(N->getConstantOperandVal(0));
|
X86::CondCode CC = X86::CondCode(N->getConstantOperandVal(0));
|
||||||
SDValue EFLAGS = N->getOperand(1);
|
SDValue EFLAGS = N->getOperand(1);
|
||||||
|
|
||||||
|
if (CC == X86::COND_A) {
|
||||||
|
// Try to convert COND_A into COND_B in an attempt to facilitate
|
||||||
|
// materializing "setb reg".
|
||||||
|
//
|
||||||
|
// Do not flip "e > c", where "c" is a constant, because Cmp instruction
|
||||||
|
// cannot take an immediate as its first operand.
|
||||||
|
//
|
||||||
|
if (EFLAGS.getOpcode() == X86ISD::SUB && EFLAGS.hasOneUse() &&
|
||||||
|
EFLAGS.getValueType().isInteger() &&
|
||||||
|
!isa<ConstantSDNode>(EFLAGS.getOperand(1))) {
|
||||||
|
SDValue NewSub = DAG.getNode(X86ISD::SUB, EFLAGS.getDebugLoc(),
|
||||||
|
EFLAGS.getNode()->getVTList(),
|
||||||
|
EFLAGS.getOperand(1), EFLAGS.getOperand(0));
|
||||||
|
SDValue NewEFLAGS = SDValue(NewSub.getNode(), EFLAGS.getResNo());
|
||||||
|
return MaterializeSETB(DL, NewEFLAGS, DAG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Materialize "setb reg" as "sbb reg,reg", since it can be extended without
|
// Materialize "setb reg" as "sbb reg,reg", since it can be extended without
|
||||||
// a zext and produces an all-ones bit which is more useful than 0/1 in some
|
// a zext and produces an all-ones bit which is more useful than 0/1 in some
|
||||||
// cases.
|
// cases.
|
||||||
if (CC == X86::COND_B)
|
if (CC == X86::COND_B)
|
||||||
return DAG.getNode(ISD::AND, DL, MVT::i8,
|
return MaterializeSETB(DL, EFLAGS, DAG);
|
||||||
DAG.getNode(X86ISD::SETCC_CARRY, DL, MVT::i8,
|
|
||||||
DAG.getConstant(CC, MVT::i8), EFLAGS),
|
|
||||||
DAG.getConstant(1, MVT::i8));
|
|
||||||
|
|
||||||
SDValue Flags;
|
SDValue Flags;
|
||||||
|
|
||||||
|
@ -30,4 +30,17 @@ entry:
|
|||||||
ret i32 %z.0
|
ret i32 %z.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; <rdar://problem/12579915>
|
||||||
|
define i32 @test3(i32 %x, i32 %y, i32 %res) nounwind uwtable readnone ssp {
|
||||||
|
entry:
|
||||||
|
%cmp = icmp ugt i32 %x, %y
|
||||||
|
%dec = sext i1 %cmp to i32
|
||||||
|
%dec.res = add nsw i32 %dec, %res
|
||||||
|
ret i32 %dec.res
|
||||||
|
; CHECK: test3:
|
||||||
|
; CHECK: cmpl
|
||||||
|
; CHECK: sbbl
|
||||||
|
; CHECK: ret
|
||||||
|
}
|
||||||
|
|
||||||
declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone
|
declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone
|
||||||
|
@ -219,7 +219,6 @@ entry:
|
|||||||
; by sbb, we should not optimize cmp away.
|
; by sbb, we should not optimize cmp away.
|
||||||
define i32 @q(i32 %j.4, i32 %w, i32 %el) {
|
define i32 @q(i32 %j.4, i32 %w, i32 %el) {
|
||||||
; CHECK: q:
|
; CHECK: q:
|
||||||
; CHECK: sub
|
|
||||||
; CHECK: cmp
|
; CHECK: cmp
|
||||||
; CHECK-NEXT: sbb
|
; CHECK-NEXT: sbb
|
||||||
%tmp532 = add i32 %j.4, %w
|
%tmp532 = add i32 %j.4, %w
|
||||||
|
Loading…
x
Reference in New Issue
Block a user