Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 487c636

Browse files
authored
Merge pull request #98 from alexcrichton/fix-wasm
Backport some wasm fixes
2 parents e45c75d + 88bda2e commit 487c636

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

include/llvm/Target/TargetLowering.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,9 @@ class TargetLowering : public TargetLoweringBase {
25892589
// TargetLowering::LowerCall that perform tail call conversions.
25902590
bool IsTailCall;
25912591

2592+
// Is Call lowering done post SelectionDAG type legalization.
2593+
bool IsPostTypeLegalization = false;
2594+
25922595
unsigned NumFixedArgs;
25932596
CallingConv::ID CallConv;
25942597
SDValue Callee;
@@ -2714,6 +2717,11 @@ class TargetLowering : public TargetLoweringBase {
27142717
return *this;
27152718
}
27162719

2720+
CallLoweringInfo &setIsPostTypeLegalization(bool Value=true) {
2721+
IsPostTypeLegalization = Value;
2722+
return *this;
2723+
}
2724+
27172725
ArgListTy &getArgs() {
27182726
return Args;
27192727
}

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,8 @@ SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node,
19411941
std::move(Args))
19421942
.setTailCall(isTailCall)
19431943
.setSExtResult(isSigned)
1944-
.setZExtResult(!isSigned);
1944+
.setZExtResult(!isSigned)
1945+
.setIsPostTypeLegalization(true);
19451946

19461947
std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
19471948

@@ -1979,7 +1980,8 @@ SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, EVT RetVT,
19791980
.setLibCallee(TLI.getLibcallCallingConv(LC), RetTy, Callee,
19801981
std::move(Args))
19811982
.setSExtResult(isSigned)
1982-
.setZExtResult(!isSigned);
1983+
.setZExtResult(!isSigned)
1984+
.setIsPostTypeLegalization(true);
19831985

19841986
std::pair<SDValue,SDValue> CallInfo = TLI.LowerCallTo(CLI);
19851987

@@ -3525,16 +3527,10 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
35253527
SDValue Args[] = { HiLHS, LHS, HiRHS, RHS };
35263528
Ret = ExpandLibCall(LC, WideVT, Args, 4, isSigned, dl);
35273529
}
3528-
BottomHalf = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, VT, Ret,
3529-
DAG.getIntPtrConstant(0, dl));
3530-
TopHalf = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, VT, Ret,
3531-
DAG.getIntPtrConstant(1, dl));
3532-
// Ret is a node with an illegal type. Because such things are not
3533-
// generally permitted during this phase of legalization, make sure the
3534-
// node has no more uses. The above EXTRACT_ELEMENT nodes should have been
3535-
// folded.
3536-
assert(Ret->use_empty() &&
3537-
"Unexpected uses of illegally type from expanded lib call.");
3530+
assert(Ret.getOpcode() == ISD::MERGE_VALUES &&
3531+
"Ret value is a collection of constituent nodes holding result.");
3532+
BottomHalf = Ret.getOperand(0);
3533+
TopHalf = Ret.getOperand(1);
35383534
}
35393535

35403536
if (isSigned) {

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7658,6 +7658,22 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
76587658
auto &DL = CLI.DAG.getDataLayout();
76597659
ComputeValueVTs(*this, DL, CLI.RetTy, RetTys, &Offsets);
76607660

7661+
if (CLI.IsPostTypeLegalization) {
7662+
// If we are lowering a libcall after legalization, split the return type.
7663+
SmallVector<EVT, 4> OldRetTys = std::move(RetTys);
7664+
SmallVector<uint64_t, 4> OldOffsets = std::move(Offsets);
7665+
for (size_t i = 0, e = OldRetTys.size(); i != e; ++i) {
7666+
EVT RetVT = OldRetTys[i];
7667+
uint64_t Offset = OldOffsets[i];
7668+
MVT RegisterVT = getRegisterType(CLI.RetTy->getContext(), RetVT);
7669+
unsigned NumRegs = getNumRegisters(CLI.RetTy->getContext(), RetVT);
7670+
unsigned RegisterVTByteSZ = RegisterVT.getSizeInBits() / 8;
7671+
RetTys.append(NumRegs, RegisterVT);
7672+
for (unsigned j = 0; j != NumRegs; ++j)
7673+
Offsets.push_back(Offset + j * RegisterVTByteSZ);
7674+
}
7675+
}
7676+
76617677
SmallVector<ISD::OutputArg, 4> Outs;
76627678
GetReturnInfo(CLI.RetTy, getReturnAttrs(CLI), Outs, *this, DL);
76637679

@@ -7738,6 +7754,7 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
77387754
for (unsigned i = 0, e = Args.size(); i != e; ++i) {
77397755
SmallVector<EVT, 4> ValueVTs;
77407756
ComputeValueVTs(*this, DL, Args[i].Ty, ValueVTs);
7757+
// FIXME: Split arguments if CLI.IsPostTypeLegalization
77417758
Type *FinalType = Args[i].Ty;
77427759
if (Args[i].isByVal)
77437760
FinalType = cast<PointerType>(Args[i].Ty)->getElementType();

test/CodeGen/WebAssembly/umulo-i64.ll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llc < %s -asm-verbose=false | FileCheck %s
2+
; Test that UMULO works correctly on 64-bit operands.
3+
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4+
target triple = "wasm32-unknown-unknown"
5+
6+
; CHECK-LABEL: _ZN4core3num21_$LT$impl$u20$u64$GT$15overflowing_mul17h07be88b4cbac028fE:
7+
; CHECK: __multi3
8+
; Function Attrs: inlinehint
9+
define void @"_ZN4core3num21_$LT$impl$u20$u64$GT$15overflowing_mul17h07be88b4cbac028fE"(i64, i64) unnamed_addr #0 {
10+
start:
11+
%2 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %0, i64 %1)
12+
%3 = extractvalue { i64, i1 } %2, 0
13+
store i64 %3, i64* undef
14+
unreachable
15+
}
16+
17+
; Function Attrs: nounwind readnone speculatable
18+
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #1
19+
20+
attributes #0 = { inlinehint }
21+
attributes #1 = { nounwind readnone speculatable }
22+
23+
; CHECK-LABEL: wut:
24+
; CHECK: call __multi3@FUNCTION, $2, $0, $pop0, $1, $pop10
25+
; CHECK: i64.load $0=, 8($2)
26+
define i1 @wut(i64, i64) {
27+
start:
28+
%2 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %0, i64 %1)
29+
%3 = extractvalue { i64, i1 } %2, 1
30+
ret i1 %3
31+
}
32+

0 commit comments

Comments
 (0)