Skip to content

Commit 574c969

Browse files
committed
Simplify patterns
1 parent d91592a commit 574c969

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
@@ -14554,44 +14554,43 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const {
1455414554
}
1455514555
}
1455614556

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

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)