diff options
author | Bill Wendling <isanbard@gmail.com> | 2008-12-09 22:08:41 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2008-12-09 22:08:41 +0000 |
commit | 74c376529101acbe141a256d0bf23a44eb454c84 (patch) | |
tree | 1876d85236de9f0268a586dcedb5e9cfb6d4167d /lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | |
parent | bc99be10b815e0bfc5102bd5746e9a80feebf6f4 (diff) |
Add sub/mul overflow intrinsics. This currently doesn't have a
target-independent way of determining overflow on multiplication. It's very
tricky. Patch by Zoltan Varga!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp')
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index e8987c54af..5d81d224c8 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -2968,6 +2968,23 @@ SelectionDAGLowering::implVisitBinaryAtomic(CallInst& I, ISD::NodeType Op) { return 0; } +// implVisitAluOverflow - Lower an overflow instrinsics +const char * +SelectionDAGLowering::implVisitAluOverflow(CallInst &I, ISD::NodeType Op) { + SDValue Op1 = getValue(I.getOperand(1)); + SDValue Op2 = getValue(I.getOperand(2)); + + MVT ValueVTs[] = { Op1.getValueType(), MVT::i1 }; + SDValue Ops[] = { Op1, Op2 }; + + SDValue Result = + DAG.getNode(Op, + DAG.getVTList(&ValueVTs[0], 2), &Ops[0], 2); + + setValue(&I, Result); + return 0; + } + /// visitExp - Lower an exp intrinsic. Handles the special sequences for /// limited-precision mode. void @@ -4097,21 +4114,17 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { } case Intrinsic::uadd_with_overflow: - case Intrinsic::sadd_with_overflow: { - SDValue Op1 = getValue(I.getOperand(1)); - SDValue Op2 = getValue(I.getOperand(2)); - - MVT ValueVTs[] = { Op1.getValueType(), MVT::i1 }; - SDValue Ops[] = { Op1, Op2 }; - - SDValue Result = - DAG.getNode((Intrinsic == Intrinsic::sadd_with_overflow) ? - ISD::SADDO : ISD::UADDO, - DAG.getVTList(&ValueVTs[0], 2), &Ops[0], 2); - - setValue(&I, Result); - return 0; - } + return implVisitAluOverflow(I, ISD::UADDO); + case Intrinsic::sadd_with_overflow: + return implVisitAluOverflow(I, ISD::SADDO); + case Intrinsic::usub_with_overflow: + return implVisitAluOverflow(I, ISD::USUBO); + case Intrinsic::ssub_with_overflow: + return implVisitAluOverflow(I, ISD::SSUBO); + case Intrinsic::umul_with_overflow: + return implVisitAluOverflow(I, ISD::UMULO); + case Intrinsic::smul_with_overflow: + return implVisitAluOverflow(I, ISD::SMULO); case Intrinsic::prefetch: { SDValue Ops[4]; |