Skip to content

Commit a0d00c9

Browse files
authored
[SimplifyCFG] Swap range metadata to attribute for calls. (#108984)
Among the last usages of range metadata for call before being able to deprecate and only have the range attribute for calls.
1 parent 0050503 commit a0d00c9

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,7 +3334,7 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
33343334
// extended for vector types in the future.
33353335
assert(!getLoadStoreType(I)->isVectorTy() && "not implemented");
33363336
auto *Op0 = I->getOperand(0);
3337-
Instruction *MaskedLoadStore = nullptr;
3337+
CallInst *MaskedLoadStore = nullptr;
33383338
if (auto *LI = dyn_cast<LoadInst>(I)) {
33393339
// Handle Load.
33403340
auto *Ty = I->getType();
@@ -3367,8 +3367,9 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
33673367
// vector specifies a per-element range, so the semantics stay the
33683368
// same. Keep it.
33693369
// !annotation: Not impact semantics. Keep it.
3370-
I->dropUBImplyingAttrsAndUnknownMetadata(
3371-
{LLVMContext::MD_range, LLVMContext::MD_annotation});
3370+
if (const MDNode *Ranges = I->getMetadata(LLVMContext::MD_range))
3371+
MaskedLoadStore->addRangeRetAttr(getConstantRangeFromMetadata(*Ranges));
3372+
I->dropUBImplyingAttrsAndUnknownMetadata({LLVMContext::MD_annotation});
33723373
// FIXME: DIAssignID is not supported for masked store yet.
33733374
// (Verifier::visitDIAssignIDMetadata)
33743375
at::deleteAssignmentMarkers(I);

llvm/test/Transforms/SimplifyCFG/X86/hoist-loads-stores-with-cf.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ define void @nondebug_metadata(i1 %cond, ptr %p, ptr %q) {
206206
; CHECK-LABEL: @nondebug_metadata(
207207
; CHECK-NEXT: entry:
208208
; CHECK-NEXT: [[TMP0:%.*]] = bitcast i1 [[COND:%.*]] to <1 x i1>
209-
; CHECK-NEXT: [[TMP1:%.*]] = call <1 x i16> @llvm.masked.load.v1i16.p0(ptr [[P:%.*]], i32 2, <1 x i1> [[TMP0]], <1 x i16> poison), !range [[RNG5:![0-9]+]]
209+
; CHECK-NEXT: [[TMP1:%.*]] = call range(i16 0, 10) <1 x i16> @llvm.masked.load.v1i16.p0(ptr [[P:%.*]], i32 2, <1 x i1> [[TMP0]], <1 x i16> poison)
210210
; CHECK-NEXT: [[TMP2:%.*]] = bitcast <1 x i16> [[TMP1]] to i16
211-
; CHECK-NEXT: [[TMP3:%.*]] = call <1 x i32> @llvm.masked.load.v1i32.p0(ptr [[Q:%.*]], i32 4, <1 x i1> [[TMP0]], <1 x i32> poison), !annotation [[META6:![0-9]+]]
211+
; CHECK-NEXT: [[TMP3:%.*]] = call <1 x i32> @llvm.masked.load.v1i32.p0(ptr [[Q:%.*]], i32 4, <1 x i1> [[TMP0]], <1 x i32> poison), !annotation [[META5:![0-9]+]]
212212
; CHECK-NEXT: [[TMP4:%.*]] = bitcast <1 x i32> [[TMP3]] to i32
213213
; CHECK-NEXT: [[TMP5:%.*]] = bitcast i16 [[TMP2]] to <1 x i16>
214-
; CHECK-NEXT: call void @llvm.masked.store.v1i16.p0(<1 x i16> [[TMP5]], ptr [[Q]], i32 4, <1 x i1> [[TMP0]]), !annotation [[META6]]
214+
; CHECK-NEXT: call void @llvm.masked.store.v1i16.p0(<1 x i16> [[TMP5]], ptr [[Q]], i32 4, <1 x i1> [[TMP0]]), !annotation [[META5]]
215215
; CHECK-NEXT: [[TMP6:%.*]] = bitcast i32 [[TMP4]] to <1 x i32>
216216
; CHECK-NEXT: call void @llvm.masked.store.v1i32.p0(<1 x i32> [[TMP6]], ptr [[P]], i32 2, <1 x i1> [[TMP0]])
217217
; CHECK-NEXT: ret void
@@ -583,7 +583,7 @@ define void @not_likely_to_execute(ptr %p, ptr %q, i32 %a) {
583583
; CHECK-LABEL: @not_likely_to_execute(
584584
; CHECK-NEXT: entry:
585585
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[A:%.*]], 0
586-
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]], !prof [[PROF7:![0-9]+]]
586+
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]], !prof [[PROF6:![0-9]+]]
587587
; CHECK: if.end:
588588
; CHECK-NEXT: ret void
589589
; CHECK: if.then:

0 commit comments

Comments
 (0)