Skip to content

Commit a8fc8d1

Browse files
committed
Add testcase
Signed-off-by: John Lu <[email protected]>
1 parent 400d08d commit a8fc8d1

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14961,14 +14961,14 @@ SDValue DAGCombiner::reduceLoadWidth(SDNode *N) {
1496114961
const MDNode *OldRanges = LN0->getRanges();
1496214962
const MDNode *NewRanges = nullptr;
1496314963
// If LSBs are loaded and the truncated ConstantRange for the OldRanges
14964-
// metadata is not the full-set for the NewWidth then create a NewRanges
14964+
// metadata is not the full-set for the new width then create a NewRanges
1496514965
// metadata for the truncated load
1496614966
if (ShAmt == 0 && OldRanges) {
1496714967
ConstantRange CR = getConstantRangeFromMetadata(*OldRanges);
1496814968

14969-
// FIXME: OldRanges should match the width of the old load, so
14970-
// CR.getBitWidth() should be wider than the new narrower load. This
14971-
// check should be unnecessary.
14969+
// It is possible for an 8-bit extending load with 8-bit range
14970+
// metadata to be narrowed to an 8-bit load. This guard is necessary to
14971+
// ensure that truncation is strictly smaller.
1497214972
if (CR.getBitWidth() > VT.getScalarSizeInBits()) {
1497314973
ConstantRange TruncatedCR = CR.truncate(VT.getScalarSizeInBits());
1497414974
if (!TruncatedCR.isFullSet()) {
@@ -14979,7 +14979,8 @@ SDValue DAGCombiner::reduceLoadWidth(SDNode *N) {
1497914979
ConstantInt::get(*DAG.getContext(), TruncatedCR.getUpper()))};
1498014980
NewRanges = MDNode::get(*DAG.getContext(), Bounds);
1498114981
}
14982-
}
14982+
} else if (CR.getBitWidth() == VT.getScalarSizeInBits())
14983+
NewRanges = OldRanges;
1498314984
}
1498414985
Load = DAG.getLoad(
1498514986
VT, DL, LN0->getChain(), NewPtr,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; RUN: llc < %s
2+
;
3+
; This test case is reduced from RangeConstraintManager.cpp in a ASan build.
4+
; It crashes reduceLoadWidth in DAGCombiner.cpp. Preservation of range
5+
; metdata must ensure that ConstantRange truncation is strictly smaller.
6+
7+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
8+
target triple = "x86_64-unknown-linux-gnu"
9+
10+
define ptr @_ZN12_GLOBAL__N_121SymbolicRangeInferrer19VisitBinaryOperatorILN5clang18BinaryOperatorKindE15EEENS2_4ento8RangeSetES5_S5_NS2_8QualTypeE() {
11+
entry:
12+
%0 = load i8, ptr null, align 4, !range !0, !noundef !1
13+
%retval.sroa.1.0.insert.ext.i = zext i8 %0 to i64
14+
%retval.sroa.1.0.insert.shift.i = shl i64 %retval.sroa.1.0.insert.ext.i, 32
15+
%coerce.val.ii = trunc i64 %retval.sroa.1.0.insert.shift.i to i40
16+
store i40 %coerce.val.ii, ptr null, align 4
17+
ret ptr null
18+
}
19+
20+
!0 = !{i8 0, i8 2}
21+
!1 = !{}

0 commit comments

Comments
 (0)