Skip to content

Commit 8937252

Browse files
committed
[DAG] computeKnownBits - add basic shift-by-parts handling
Concat KnownBits from ISD::SHL_PARTS / ISD::SRA_PARTS / ISD::SRL_PARTS lo/hi operands and perform the KnownBits calculation by the shift amount on the extended type, before splitting the KnownBits based on the requested lo/hi result.
1 parent 380a1b2 commit 8937252

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,6 +3337,38 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
33373337
Known.Zero |= Known2.Zero;
33383338
}
33393339
break;
3340+
case ISD::SHL_PARTS:
3341+
case ISD::SRA_PARTS:
3342+
case ISD::SRL_PARTS: {
3343+
assert((Op.getResNo() == 0 || Op.getResNo() == 1) && "Unknown result");
3344+
3345+
// Collect lo/hi source values and concatenate.
3346+
// TODO: Would a KnownBits::concatBits helper be useful?
3347+
unsigned LoBits = Op.getOperand(0).getScalarValueSizeInBits();
3348+
unsigned HiBits = Op.getOperand(1).getScalarValueSizeInBits();
3349+
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
3350+
Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
3351+
Known = Known.anyext(LoBits + HiBits);
3352+
Known.insertBits(Known2, LoBits);
3353+
3354+
// Collect shift amount.
3355+
Known2 = computeKnownBits(Op.getOperand(2), DemandedElts, Depth + 1);
3356+
3357+
if (Opcode == ISD::SHL_PARTS)
3358+
Known = KnownBits::shl(Known, Known2);
3359+
else if (Opcode == ISD::SRA_PARTS)
3360+
Known = KnownBits::ashr(Known, Known2);
3361+
else // if (Opcode == ISD::SRL_PARTS)
3362+
Known = KnownBits::lshr(Known, Known2);
3363+
3364+
// TODO: Minimum shift low/high bits are known zero.
3365+
3366+
if (Op.getResNo() == 0)
3367+
Known = Known.extractBits(LoBits, 0);
3368+
else
3369+
Known = Known.extractBits(HiBits, LoBits);
3370+
break;
3371+
}
33403372
case ISD::SIGN_EXTEND_INREG: {
33413373
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
33423374
EVT EVT = cast<VTSDNode>(Op.getOperand(1))->getVT();

llvm/test/CodeGen/X86/shift-parts.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ define i32 @int87(i32 %uint64p_8, i1 %cond) nounwind {
1919
; CHECK-NEXT: testb $64, %dl
2020
; CHECK-NEXT: movq %rcx, %rsi
2121
; CHECK-NEXT: cmovneq %rax, %rsi
22-
; CHECK-NEXT: orl $0, %esi
22+
; CHECK-NEXT: testl %esi, %esi
2323
; CHECK-NEXT: je .LBB0_1
2424
; CHECK-NEXT: # %bb.2: # %if.then
2525
; CHECK-NEXT: movl $1, %eax

0 commit comments

Comments
 (0)