Skip to content

Commit 7483e99

Browse files
committed
Support i16 to i32 case
1 parent 6ebf514 commit 7483e99

File tree

2 files changed

+48
-27
lines changed

2 files changed

+48
-27
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14436,20 +14436,44 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const {
1443614436
}
1443714437
}
1443814438

14439-
// Combine (a-2^(M-1)) => sext(trunc(a, M), 64)
14440-
if (CC == ISD::SETULT && LHS.getOpcode() == ISD::ADD && OpVT == MVT::i64 &&
14441-
isa<ConstantSDNode>(RHS) && isa<ConstantSDNode>(LHS.getOperand(1))) {
14442-
uint64_t ShiftVal =
14443-
~(cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue()) + 1;
14444-
uint64_t CmpVal = ~(cast<ConstantSDNode>(RHS)->getZExtValue()) + 1;
14445-
if (isPowerOf2_64(ShiftVal) && ShiftVal << 1 == CmpVal) {
14446-
unsigned DestBits = Log2_64(CmpVal);
14447-
if (DestBits == 8 || DestBits == 16 || DestBits == 32) {
14448-
SDValue Conv =
14449-
DAG.getSExtOrTrunc(DAG.getSExtOrTrunc(LHS.getOperand(0), DL,
14450-
MVT::getIntegerVT(DestBits)),
14451-
DL, OpVT);
14452-
return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14439+
if (CC == ISD::SETULT && isa<ConstantSDNode>(RHS)) {
14440+
uint64_t RHSVal = cast<ConstantSDNode>(RHS)->getZExtValue();
14441+
if (LHS.getOpcode() == ISD::ADD && isa<ConstantSDNode>(LHS.getOperand(1))) {
14442+
uint64_t Addend = cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue();
14443+
if (OpVT == MVT::i64) {
14444+
// (a-2^(M-1)) => sext(trunc(a, M), 64)
14445+
uint64_t ShiftVal = ~Addend + 1;
14446+
uint64_t CmpVal = ~RHSVal + 1;
14447+
if (isPowerOf2_64(ShiftVal) && ShiftVal << 1 == CmpVal) {
14448+
unsigned DestBits = Log2_64(CmpVal);
14449+
if (DestBits == 8 || DestBits == 16 || DestBits == 32) {
14450+
SDValue Conv = DAG.getSExtOrTrunc(
14451+
DAG.getSExtOrTrunc(LHS.getOperand(0), DL,
14452+
MVT::getIntegerVT(DestBits)),
14453+
DL, OpVT);
14454+
return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14455+
}
14456+
}
14457+
} else if (OpVT == MVT::i32) {
14458+
if (RHSVal == 0xffffff00 && Addend == 0xffffff80) {
14459+
SDValue Conv = DAG.getSExtOrTrunc(
14460+
DAG.getSExtOrTrunc(LHS.getOperand(0), DL, MVT::i8), DL, OpVT);
14461+
return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14462+
}
14463+
}
14464+
} else if (LHS.getOpcode() == ISD::SRL &&
14465+
LHS.getOperand(0).getOpcode() == ISD::ADD &&
14466+
isa<ConstantSDNode>(LHS.getOperand(1)) &&
14467+
isa<ConstantSDNode>(LHS.getOperand(0).getOperand(1))) {
14468+
if (RHSVal == 65535 &&
14469+
cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue() == 16 &&
14470+
cast<ConstantSDNode>(LHS.getOperand(0).getOperand(1))
14471+
->getZExtValue() == 0xffff8000) {
14472+
SDValue Conv = DAG.getSExtOrTrunc(
14473+
DAG.getSExtOrTrunc(LHS.getOperand(0).getOperand(0), DL, MVT::i16),
14474+
DL, OpVT);
14475+
return DAG.getSetCC(DL, VT, LHS.getOperand(0).getOperand(0), Conv,
14476+
ISD::SETNE);
1445314477
}
1445414478
}
1445514479
}

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ entry:
134134
define zeroext i1 @test8(i32 %a) {
135135
; CHECK-LABEL: test8:
136136
; CHECK: # %bb.0: # %entry
137-
; CHECK-NEXT: addi 3, 3, -32768
138-
; CHECK-NEXT: lis 4, -1
139-
; CHECK-NEXT: rlwinm 3, 3, 16, 16, 31
140-
; CHECK-NEXT: ori 4, 4, 1
141-
; CHECK-NEXT: add 3, 3, 4
142-
; CHECK-NEXT: rldicl 3, 3, 1, 63
137+
; CHECK-NEXT: extsh 4, 3
138+
; CHECK-NEXT: xor 3, 3, 4
139+
; CHECK-NEXT: cntlzw 3, 3
140+
; CHECK-NEXT: srwi 3, 3, 5
141+
; CHECK-NEXT: xori 3, 3, 1
143142
; CHECK-NEXT: blr
144143
entry:
145144
%0 = add i32 %a, -32768
@@ -150,13 +149,11 @@ entry:
150149
define zeroext i1 @test9(i32 %a) {
151150
; CHECK-LABEL: test9:
152151
; CHECK: # %bb.0: # %entry
153-
; CHECK-NEXT: lis 4, -256
154-
; CHECK-NEXT: addi 3, 3, -128
155-
; CHECK-NEXT: ori 4, 4, 1
156-
; CHECK-NEXT: clrldi 3, 3, 32
157-
; CHECK-NEXT: rldic 4, 4, 8, 0
158-
; CHECK-NEXT: add 3, 3, 4
159-
; CHECK-NEXT: rldicl 3, 3, 1, 63
152+
; CHECK-NEXT: extsb 4, 3
153+
; CHECK-NEXT: xor 3, 3, 4
154+
; CHECK-NEXT: cntlzw 3, 3
155+
; CHECK-NEXT: srwi 3, 3, 5
156+
; CHECK-NEXT: xori 3, 3, 1
160157
; CHECK-NEXT: blr
161158
entry:
162159
%0 = add i32 %a, -128

0 commit comments

Comments
 (0)