[llvm-commits] [llvm] r133288 - in /llvm/trunk: include/llvm/CodeGen/RuntimeLibcalls.h lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp lib/CodeGen/SelectionDAG/LegalizeTypes.h lib/CodeGen/SelectionDAG/TargetLowering.cpp test/CodeGen/X86/muloti.ll

Duncan Sands baldrick at free.fr
Sun Jun 19 06:05:52 PDT 2011


Hi Eric,

> Lower multiply with overflow checking to __mulo<mode>
> calls if we haven't been able to lower them any
> other way.

> +void DAGTypeLegalizer::ExpandIntRes_XMULO(SDNode *N,
> +                                          SDValue&Lo, SDValue&Hi) {
> +  EVT VT = N->getValueType(0);
> +  const Type *RetTy = VT.getTypeForEVT(*DAG.getContext());
> +  EVT PtrVT = TLI.getPointerTy();
> +  const Type *PtrTy = PtrVT.getTypeForEVT(*DAG.getContext());
> +  DebugLoc dl = N->getDebugLoc();
> +
> +  // Expand the result by simply replacing it with the equivalent
> +  // non-overflow-checking operation.

where do you actually do this (see comment)?  I see you replacing the overflow
result, but not the multiplication result...

> +  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
> +  if (VT == MVT::i32)
> +    LC = RTLIB::MULO_I32;
> +  else if (VT == MVT::i64)
> +    LC = RTLIB::MULO_I64;
> +  else if (VT == MVT::i128)
> +    LC = RTLIB::MULO_I128;
> +  assert(LC != RTLIB::UNKNOWN_LIBCALL&&  "Unsupported XMULO!");
> +
> +  SDValue Temp = DAG.CreateStackTemporary(PtrVT);
> +  // Temporary for the overflow value, default it to zero.
> +  SDValue Chain = DAG.getStore(DAG.getEntryNode(), dl,
> +			       DAG.getConstant(0, PtrVT), Temp,
> +			       MachinePointerInfo(), false, false, 0);
> +
> +  TargetLowering::ArgListTy Args;
> +  TargetLowering::ArgListEntry Entry;
> +  for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
> +    EVT ArgVT = N->getOperand(i).getValueType();
> +    const Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext());
> +    Entry.Node = N->getOperand(i);
> +    Entry.Ty = ArgTy;
> +    Entry.isSExt = true;
> +    Entry.isZExt = false;
> +    Args.push_back(Entry);
> +  }
> +
> +  // Also pass the address of the overflow check.
> +  Entry.Node = Temp;
> +  Entry.Ty = PtrTy->getPointerTo();
> +  Entry.isSExt = true;
> +  Entry.isZExt = false;
> +  Args.push_back(Entry);
> +
> +  SDValue Func = DAG.getExternalSymbol(TLI.getLibcallName(LC), PtrVT);
> +  std::pair<SDValue, SDValue>  CallInfo =
> +    TLI.LowerCallTo(Chain, RetTy, true, false, false, false,
> +		    0, TLI.getLibcallCallingConv(LC), false,
> +		    true, Func, Args, DAG, dl);

Can you not use MakeLibCall for most of this?

Ciao, Duncan.



More information about the llvm-commits mailing list