@@ -4487,6 +4487,18 @@ static const MDNode *getRangeMetadata(const Instruction &I) {
4487
4487
return I.getMetadata(LLVMContext::MD_range);
4488
4488
}
4489
4489
4490
+ static std::optional<ConstantRange> getRange(const Instruction &I) {
4491
+ if (const auto *CB = dyn_cast<CallBase>(&I)) {
4492
+ // see comment in getRangeMetadata about this check
4493
+ if (CB->hasRetAttr(Attribute::NoUndef))
4494
+ return CB->getRange();
4495
+ }
4496
+ if (const MDNode *Range = getRangeMetadata(I)) {
4497
+ return getConstantRangeFromMetadata(*Range);
4498
+ }
4499
+ return std::nullopt;
4500
+ }
4501
+
4490
4502
void SelectionDAGBuilder::visitLoad(const LoadInst &I) {
4491
4503
if (I.isAtomic())
4492
4504
return visitAtomicLoad(I);
@@ -10229,19 +10241,16 @@ void SelectionDAGBuilder::visitVACopy(const CallInst &I) {
10229
10241
SDValue SelectionDAGBuilder::lowerRangeToAssertZExt(SelectionDAG &DAG,
10230
10242
const Instruction &I,
10231
10243
SDValue Op) {
10232
- const MDNode *Range = getRangeMetadata(I);
10233
- if (!Range)
10234
- return Op;
10244
+ std::optional<ConstantRange> CR = getRange(I);
10235
10245
10236
- ConstantRange CR = getConstantRangeFromMetadata(*Range);
10237
- if (CR.isFullSet() || CR.isEmptySet() || CR.isUpperWrapped())
10246
+ if (!CR || CR->isFullSet() || CR->isEmptySet() || CR->isUpperWrapped())
10238
10247
return Op;
10239
10248
10240
- APInt Lo = CR. getUnsignedMin();
10249
+ APInt Lo = CR-> getUnsignedMin();
10241
10250
if (!Lo.isMinValue())
10242
10251
return Op;
10243
10252
10244
- APInt Hi = CR. getUnsignedMax();
10253
+ APInt Hi = CR-> getUnsignedMax();
10245
10254
unsigned Bits = std::max(Hi.getActiveBits(),
10246
10255
static_cast<unsigned>(IntegerType::MIN_INT_BITS));
10247
10256
0 commit comments