mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
X86: optimization for -(x != 0)
This patch will optimize -(x != 0) on X86 FROM cmpl $0x01,%edi sbbl %eax,%eax notl %eax TO negl %edi sbbl %eax %eax In order to generate negl, I added patterns in Target/X86/X86InstrCompiler.td: def : Pat<(X86sub_flag 0, GR32:$src), (NEG32r GR32:$src)>; rdar: 10961709 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156312 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
af97f73ca0
commit
ed57984483
@ -8665,6 +8665,22 @@ SDValue X86TargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const {
|
||||
SDValue Y = isAllOnes(Op2) ? Op1 : Op2;
|
||||
|
||||
SDValue CmpOp0 = Cmp.getOperand(0);
|
||||
// Apply further optimizations for special cases
|
||||
// (select (x != 0), -1, 0) -> neg & sbb
|
||||
// (select (x == 0), 0, -1) -> neg & sbb
|
||||
if (ConstantSDNode *YC = dyn_cast<ConstantSDNode>(Y))
|
||||
if (YC->isNullValue() &&
|
||||
(isAllOnes(Op1) == (CondCode == X86::COND_NE))) {
|
||||
SDVTList VTs = DAG.getVTList(CmpOp0.getValueType(), MVT::i32);
|
||||
SDValue Neg = DAG.getNode(X86ISD::SUB, DL, VTs,
|
||||
DAG.getConstant(0, CmpOp0.getValueType()),
|
||||
CmpOp0);
|
||||
SDValue Res = DAG.getNode(X86ISD::SETCC_CARRY, DL, Op.getValueType(),
|
||||
DAG.getConstant(X86::COND_B, MVT::i8),
|
||||
SDValue(Neg.getNode(), 1));
|
||||
return Res;
|
||||
}
|
||||
|
||||
Cmp = DAG.getNode(X86ISD::CMP, DL, MVT::i32,
|
||||
CmpOp0, DAG.getConstant(1, CmpOp0.getValueType()));
|
||||
Cmp = ConvertCmpIfNecessary(Cmp, DAG);
|
||||
|
@ -1623,6 +1623,12 @@ def : Pat<(sub GR16:$src1, i16immSExt8:$src2),
|
||||
def : Pat<(sub GR32:$src1, i32immSExt8:$src2),
|
||||
(SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
|
||||
|
||||
// sub 0, reg
|
||||
def : Pat<(X86sub_flag 0, GR8 :$src), (NEG8r GR8 :$src)>;
|
||||
def : Pat<(X86sub_flag 0, GR16:$src), (NEG16r GR16:$src)>;
|
||||
def : Pat<(X86sub_flag 0, GR32:$src), (NEG32r GR32:$src)>;
|
||||
def : Pat<(X86sub_flag 0, GR64:$src), (NEG64r GR64:$src)>;
|
||||
|
||||
// mul reg, reg
|
||||
def : Pat<(mul GR16:$src1, GR16:$src2),
|
||||
(IMUL16rr GR16:$src1, GR16:$src2)>;
|
||||
|
@ -218,3 +218,33 @@ define i32 @test14(i32 %a, i32 %b) nounwind {
|
||||
; CHECK-NEXT: ret
|
||||
}
|
||||
|
||||
; rdar://10961709
|
||||
define i32 @test15(i32 %x) nounwind {
|
||||
entry:
|
||||
%cmp = icmp ne i32 %x, 0
|
||||
%sub = sext i1 %cmp to i32
|
||||
ret i32 %sub
|
||||
; CHECK: test15:
|
||||
; CHECK: negl
|
||||
; CHECK: sbbl
|
||||
}
|
||||
|
||||
define i64 @test16(i64 %x) nounwind uwtable readnone ssp {
|
||||
entry:
|
||||
%cmp = icmp ne i64 %x, 0
|
||||
%conv1 = sext i1 %cmp to i64
|
||||
ret i64 %conv1
|
||||
; CHECK: test16:
|
||||
; CHECK: negq
|
||||
; CHECK: sbbq
|
||||
}
|
||||
|
||||
define i16 @test17(i16 %x) nounwind {
|
||||
entry:
|
||||
%cmp = icmp ne i16 %x, 0
|
||||
%sub = sext i1 %cmp to i16
|
||||
ret i16 %sub
|
||||
; CHECK: test17:
|
||||
; CHECK: negw
|
||||
; CHECK: sbbw
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user