Skip to content

Commit d897a14

Browse files
committed
[SystemZ] Fix check for zero size when lowering memcmp.
During lowering of memcmp/bcmp, the check for a size of 0 is done in 2 different ways. In rare cases this can lead to a crash in SystemZSelectionDAGInfo::EmitTargetCodeForMemcmp(). The root cause is that SelectionDAGBuilder::visitMemCmpBCmpCall() checks for a constant int value which is not yet evaluated. When the value is turned into a SDValue, then the evaluation is done and results in a ConstantSDNode. But EmitTargetCodeForMemcmp() expects the special case of 0 length to be handled, which results in an assertion. The fix is to turn the value into a SDValue, so that both functions use the same check. Reviewed By: uweigand Differential Revision: https://reviews.llvm.org/D126900
1 parent 4636b93 commit d897a14

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7902,7 +7902,7 @@ void SelectionDAGBuilder::processIntegerCallValue(const Instruction &I,
79027902
bool SelectionDAGBuilder::visitMemCmpBCmpCall(const CallInst &I) {
79037903
const Value *LHS = I.getArgOperand(0), *RHS = I.getArgOperand(1);
79047904
const Value *Size = I.getArgOperand(2);
7905-
const ConstantInt *CSize = dyn_cast<ConstantInt>(Size);
7905+
const ConstantSDNode *CSize = dyn_cast<ConstantSDNode>(getValue(Size));
79067906
if (CSize && CSize->getZExtValue() == 0) {
79077907
EVT CallVT = DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
79087908
I.getType(), true);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; Test memcmp with 0 size.
2+
3+
; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4+
; REQUIRES: asserts
5+
6+
declare i32 @memcmp(i8* nocapture, i8* nocapture, i64)
7+
8+
define hidden void @fun() {
9+
; CHECK-LABEL: fun
10+
entry:
11+
%len = extractvalue [2 x i64] zeroinitializer, 1
12+
br i1 undef, label %end, label %call
13+
14+
call:
15+
%res = tail call signext i32 @memcmp(i8* noundef undef, i8* noundef undef, i64 noundef %len)
16+
unreachable
17+
18+
end:
19+
unreachable
20+
}

0 commit comments

Comments
 (0)