Skip to content

Commit 13c49b3

Browse files
committed
Simplify patterns
1 parent 99d5773 commit 13c49b3

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14548,44 +14548,43 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const {
1454814548
}
1454914549
}
1455014550

14551-
if (CC == ISD::SETULT && isa<ConstantSDNode>(RHS)) {
14552-
uint64_t RHSVal = cast<ConstantSDNode>(RHS)->getZExtValue();
14553-
if (LHS.getOpcode() == ISD::ADD && isa<ConstantSDNode>(LHS.getOperand(1))) {
14554-
uint64_t Addend = cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue();
14555-
if (OpVT == MVT::i64) {
14556-
uint64_t ShiftVal = ~Addend + 1;
14557-
uint64_t CmpVal = ~RHSVal + 1;
14558-
if (isPowerOf2_64(ShiftVal) && ShiftVal << 1 == CmpVal) {
14559-
unsigned DestBits = Log2_64(CmpVal);
14560-
if (DestBits == 8 || DestBits == 16 || DestBits == 32) {
14561-
SDValue Conv = DAG.getSExtOrTrunc(
14562-
DAG.getSExtOrTrunc(LHS.getOperand(0), DL,
14563-
MVT::getIntegerVT(DestBits)),
14564-
DL, OpVT);
14565-
return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14566-
}
14567-
}
14568-
} else if (OpVT == MVT::i32) {
14569-
if (RHSVal == 0xffffff00 && Addend == 0xffffff80) {
14570-
SDValue Conv = DAG.getSExtOrTrunc(
14571-
DAG.getSExtOrTrunc(LHS.getOperand(0), DL, MVT::i8), DL, OpVT);
14572-
return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14573-
}
14551+
if (CC == ISD::SETULT) {
14552+
auto GetTruncExtCmp = [&](SDValue Src, EVT DstVT) {
14553+
return DAG.getSetCC(
14554+
DL, VT, Src,
14555+
DAG.getSExtOrTrunc(DAG.getSExtOrTrunc(Src, DL, DstVT), DL, OpVT),
14556+
ISD::SETNE);
14557+
};
14558+
// ult (add x -0x80000000) -0x100000000 -> ne x (sext:i64 (trunc:i32 x))
14559+
// ult (add x -0x8000) -0x10000 -> ne x (sext:i64 (trunc:i16 x))
14560+
// ult (add x -0x80) -0x100 -> ne x (sext:i64 (trunc:i8 x))
14561+
// ult (add x -0x80) -0x100 -> ne x (sext:i32 (trunc:i16 x))
14562+
// ult (add x -0x80) -0x100 -> ne x (sext:i16 (trunc:i8 x))
14563+
if (LHS.getOpcode() == ISD::ADD) {
14564+
const auto *Addend = dyn_cast<ConstantSDNode>(LHS.getOperand(1));
14565+
const auto *RhsC = dyn_cast<ConstantSDNode>(RHS);
14566+
if (Addend && RhsC) {
14567+
int64_t AddendVal = Addend->getSExtValue();
14568+
int64_t RhsVal = RhsC->getSExtValue();
14569+
if (AddendVal == -0x80000000L && RhsVal == -0x100000000L &&
14570+
OpVT == MVT::i64)
14571+
return GetTruncExtCmp(LHS.getOperand(0), MVT::i32);
14572+
if (AddendVal == -0x8000 && RhsVal == -0x10000 && OpVT == MVT::i64)
14573+
return GetTruncExtCmp(LHS.getOperand(0), MVT::i16);
14574+
if (AddendVal == -0x80 && RhsVal == -0x100 &&
14575+
(OpVT == MVT::i64 || OpVT == MVT::i32 || OpVT == MVT::i16))
14576+
return GetTruncExtCmp(LHS.getOperand(0), MVT::i8);
1457414577
}
14578+
// ult (srl (add x -0x8000) 16) 0xffff -> ne x (sext:i32 (trunc:i16 x))
1457514579
} else if (LHS.getOpcode() == ISD::SRL &&
14576-
LHS.getOperand(0).getOpcode() == ISD::ADD &&
14577-
isa<ConstantSDNode>(LHS.getOperand(1)) &&
14578-
isa<ConstantSDNode>(LHS.getOperand(0).getOperand(1))) {
14579-
if (RHSVal == 0xffff &&
14580-
cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue() == 16 &&
14581-
cast<ConstantSDNode>(LHS.getOperand(0).getOperand(1))
14582-
->getZExtValue() == 0xffff8000) {
14583-
SDValue Conv = DAG.getSExtOrTrunc(
14584-
DAG.getSExtOrTrunc(LHS.getOperand(0).getOperand(0), DL, MVT::i16),
14585-
DL, OpVT);
14586-
return DAG.getSetCC(DL, VT, LHS.getOperand(0).getOperand(0), Conv,
14587-
ISD::SETNE);
14588-
}
14580+
LHS.getOperand(0).getOpcode() == ISD::ADD) {
14581+
const auto *SrlAmt = dyn_cast<ConstantSDNode>(LHS.getOperand(1));
14582+
const auto *Addend =
14583+
dyn_cast<ConstantSDNode>(LHS.getOperand(0).getOperand(1));
14584+
const auto *RhsC = dyn_cast<ConstantSDNode>(RHS);
14585+
if (SrlAmt && Addend && RhsC && SrlAmt->getSExtValue() == 16 &&
14586+
Addend->getSExtValue() == -0x8000 && RhsC->getSExtValue() == 0xffff)
14587+
return GetTruncExtCmp(LHS.getOperand(0).getOperand(0), MVT::i8);
1458914588
}
1459014589
}
1459114590

llvm/test/CodeGen/PowerPC/setcc-to-sub.ll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ entry:
134134
define zeroext i1 @test8(i32 %a) {
135135
; CHECK-LABEL: test8:
136136
; CHECK: # %bb.0: # %entry
137-
; CHECK-NEXT: extsh 4, 3
137+
; CHECK-NEXT: extsb 4, 3
138138
; CHECK-NEXT: xor 3, 3, 4
139139
; CHECK-NEXT: cntlzw 3, 3
140140
; CHECK-NEXT: srwi 3, 3, 5
@@ -164,12 +164,13 @@ entry:
164164
define zeroext i1 @test10(i16 %a) {
165165
; CHECK-LABEL: test10:
166166
; CHECK: # %bb.0: # %entry
167-
; CHECK-NEXT: addi 3, 3, -128
168-
; CHECK-NEXT: lis 4, -1
167+
; CHECK-NEXT: clrlwi 4, 3, 16
168+
; CHECK-NEXT: extsb 3, 3
169169
; CHECK-NEXT: clrlwi 3, 3, 16
170-
; CHECK-NEXT: ori 4, 4, 256
171-
; CHECK-NEXT: add 3, 3, 4
172-
; CHECK-NEXT: rldicl 3, 3, 1, 63
170+
; CHECK-NEXT: xor 3, 4, 3
171+
; CHECK-NEXT: cntlzw 3, 3
172+
; CHECK-NEXT: srwi 3, 3, 5
173+
; CHECK-NEXT: xori 3, 3, 1
173174
; CHECK-NEXT: blr
174175
entry:
175176
%0 = add i16 %a, -128

0 commit comments

Comments
 (0)