diff options
| author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2016-10-24 21:47:19 +0000 |
|---|---|---|
| committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2016-10-24 21:47:19 +0000 |
| commit | e3e6585c2d2f57c6354825b411dec9c377fa43f3 (patch) | |
| tree | 430a98a4a80d11216e509b3555f9c0c060217069 /llvm/lib/CodeGen/SelectionDAG | |
| parent | 409252fcefacedfd18b461e219c63b84049e04ae (diff) | |
| download | bcm5719-llvm-e3e6585c2d2f57c6354825b411dec9c377fa43f3.tar.gz bcm5719-llvm-e3e6585c2d2f57c6354825b411dec9c377fa43f3.zip | |
[SelectionDAG] Update ComputeNumSignBits SRA/SHL handlers to accept scalar or vector splats
Use isConstOrConstSplat helper.
Also use APInt instead of getZExtValue directly to avoid out of range issues.
llvm-svn: 285033
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 28c3f7a9e96..c2c7bb07ca8 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2566,17 +2566,18 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, unsigned Depth) const { case ISD::SRA: Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); // SRA X, C -> adds C sign bits. - if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { - Tmp += C->getZExtValue(); - if (Tmp > VTBits) Tmp = VTBits; + if (ConstantSDNode *C = isConstOrConstSplat(Op.getOperand(1))) { + APInt ShiftVal = C->getAPIntValue(); + ShiftVal += Tmp; + Tmp = ShiftVal.uge(VTBits) ? VTBits : ShiftVal.getZExtValue(); } return Tmp; case ISD::SHL: - if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { + if (ConstantSDNode *C = isConstOrConstSplat(Op.getOperand(1))) { // shl destroys sign bits. Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); - if (C->getZExtValue() >= VTBits || // Bad shift. - C->getZExtValue() >= Tmp) break; // Shifted all sign bits out. + if (C->getAPIntValue().uge(VTBits) || // Bad shift. + C->getAPIntValue().uge(Tmp)) break; // Shifted all sign bits out. return Tmp - C->getZExtValue(); } break; |

