mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-26 07:24:25 +00:00
This is another case where instcombine demanded bits optimization created
large immediates. Add dag combine logic to recover in case the large immediates doesn't fit in cmp immediate operand field. int foo(unsigned long l) { return (l>> 47) == 1; } we produce %shr.mask = and i64 %l, -140737488355328 %cmp = icmp eq i64 %shr.mask, 140737488355328 %conv = zext i1 %cmp to i32 ret i32 %conv which codegens to movq $0xffff800000000000,%rax andq %rdi,%rax movq $0x0000800000000000,%rcx cmpq %rcx,%rax sete %al movzbl %al,%eax ret TargetLowering::SimplifySetCC would transform (X & -256) == 256 -> (X >> 8) == 1 if the immediate fails the isLegalICmpImmediate() test. For x86, that's immediates which are not a signed 32-bit immediate. Based on a patch by Eli Friedman. PR10328 rdar://9758774 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160346 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -2322,6 +2322,27 @@ TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isLegalICmpImmediate(C1.getSExtValue())) {
|
||||
// (X & -256) == 256 -> (X >> 8) == 1
|
||||
if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) &&
|
||||
N0.getOpcode() == ISD::AND && N0.hasOneUse()) {
|
||||
if (ConstantSDNode *AndRHS =
|
||||
dyn_cast<ConstantSDNode>(N0.getOperand(1))) {
|
||||
const APInt &AndRHSC = AndRHS->getAPIntValue();
|
||||
if ((-AndRHSC).isPowerOf2() && (AndRHSC & C1) == C1) {
|
||||
unsigned ShiftBits = AndRHSC.countTrailingZeros();
|
||||
EVT ShiftTy = DCI.isBeforeLegalize() ?
|
||||
getPointerTy() : getShiftAmountTy(N0.getValueType());
|
||||
EVT CmpTy = N0.getValueType();
|
||||
SDValue Shift = DAG.getNode(ISD::SRL, dl, CmpTy, N0.getOperand(0),
|
||||
DAG.getConstant(ShiftBits, ShiftTy));
|
||||
SDValue CmpRHS = DAG.getConstant(C1.lshr(ShiftBits), CmpTy);
|
||||
return DAG.getSetCC(dl, VT, Shift, CmpRHS, Cond);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isa<ConstantFPSDNode>(N0.getNode())) {
|
||||
|
Reference in New Issue
Block a user