Skip to content

Commit 04e45e9

Browse files
committedFeb 19, 2019
[SDAG] Use shift amount type in MULO promotion; NFC
Directly use the correct shift amount type if it is possible, and future-proof the code against vectors. The added test makes sure that bitwidths that do not fit into the shift amount type do not assert. Split out from D57997. llvm-svn: 354359
1 parent dce9c2a commit 04e45e9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
 

Diff for: ‎llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,11 @@ SDValue DAGTypeLegalizer::PromoteIntRes_XMULO(SDNode *N, unsigned ResNo) {
952952
SDValue Overflow;
953953
if (N->getOpcode() == ISD::UMULO) {
954954
// Unsigned overflow occurred if the high part is non-zero.
955+
unsigned Shift = SmallVT.getScalarSizeInBits();
956+
EVT ShiftTy = getShiftAmountTyForConstant(Shift, Mul.getValueType(),
957+
TLI, DAG);
955958
SDValue Hi = DAG.getNode(ISD::SRL, DL, Mul.getValueType(), Mul,
956-
DAG.getIntPtrConstant(SmallVT.getSizeInBits(),
957-
DL));
959+
DAG.getConstant(Shift, DL, ShiftTy));
958960
Overflow = DAG.getSetCC(DL, N->getValueType(1), Hi,
959961
DAG.getConstant(0, DL, Hi.getValueType()),
960962
ISD::SETNE);

Diff for: ‎llvm/test/CodeGen/X86/umul-with-overflow.ll

+9
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ entry:
6868
%tmp2 = extractvalue { i32, i1 } %tmp1, 0
6969
ret i32 %tmp2
7070
}
71+
72+
; Check that shifts larger than the shift amount type are handled.
73+
; Intentionally not testing codegen here, only that this doesn't assert.
74+
declare {i300, i1} @llvm.umul.with.overflow.i300(i300 %a, i300 %b)
75+
define i300 @test4(i300 %a, i300 %b) nounwind {
76+
%x = call {i300, i1} @llvm.umul.with.overflow.i300(i300 %a, i300 %b)
77+
%y = extractvalue {i300, i1} %x, 0
78+
ret i300 %y
79+
}

0 commit comments

Comments
 (0)
Please sign in to comment.