Skip to content

Commit e872852

Browse files
committed
[IR] Allow range assume bundles
1 parent f35a14d commit e872852

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

llvm/lib/Analysis/AssumeBundleQueries.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ bool llvm::hasAttributeInAssume(AssumeInst &Assume, Value *IsOn,
6969

7070
void llvm::fillMapFromAssume(AssumeInst &Assume, RetainedKnowledgeMap &Result) {
7171
for (auto &Bundles : Assume.bundle_op_infos()) {
72-
std::pair<Value *, Attribute::AttrKind> Key{
73-
nullptr, Attribute::getAttrKindFromName(Bundles.Tag->getKey())};
72+
Attribute::AttrKind AttrKind =
73+
Attribute::getAttrKindFromName(Bundles.Tag->getKey());
74+
75+
if (!Attribute::isEnumAttrKind(AttrKind) &&
76+
!Attribute::isIntAttrKind(AttrKind))
77+
continue;
78+
79+
std::pair<Value *, Attribute::AttrKind> Key{nullptr, AttrKind};
7480
if (bundleHasArgument(Bundles, ABA_WasOn))
7581
Key.first = getValueFromBundleOpInfo(Assume, Bundles, ABA_WasOn);
7682

@@ -101,8 +107,14 @@ llvm::getKnowledgeFromBundle(AssumeInst &Assume,
101107
RetainedKnowledge Result;
102108
if (!DebugCounter::shouldExecute(AssumeQueryCounter))
103109
return Result;
110+
Attribute::AttrKind AttrKind =
111+
Attribute::getAttrKindFromName(BOI.Tag->getKey());
112+
113+
if (!Attribute::isEnumAttrKind(AttrKind) &&
114+
!Attribute::isIntAttrKind(AttrKind))
115+
return Result;
104116

105-
Result.AttrKind = Attribute::getAttrKindFromName(BOI.Tag->getKey());
117+
Result.AttrKind = AttrKind;
106118
if (bundleHasArgument(BOI, ABA_WasOn))
107119
Result.WasOn = getValueFromBundleOpInfo(Assume, BOI, ABA_WasOn);
108120
auto GetArgOr1 = [&](unsigned Idx) -> uint64_t {

llvm/lib/IR/Verifier.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5416,6 +5416,23 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
54165416
"third argument should be an integer if present", Call);
54175417
return;
54185418
}
5419+
if (Kind == Attribute::Range) {
5420+
Check(ArgCount == 3, "range assumptions should have 3 arguments", Call);
5421+
Type *FirstType = Call.getOperand(Elem.Begin)->getType();
5422+
Check(FirstType->isIntOrIntVectorTy(),
5423+
"first argument should be an integer or vector of integers",
5424+
Call);
5425+
Type *ST = FirstType->getScalarType();
5426+
Check(Call.getOperand(Elem.Begin + 1)->getType() == ST,
5427+
"second argument should be an integer with same bit width as the "
5428+
"first argument",
5429+
Call);
5430+
Check(Call.getOperand(Elem.Begin + 2)->getType() == ST,
5431+
"third argument should be an integer with same bit width as the "
5432+
"first argument",
5433+
Call);
5434+
return;
5435+
}
54195436
Check(ArgCount <= 2, "too many arguments", Call);
54205437
if (Kind == Attribute::None)
54215438
break;

llvm/test/Verifier/assume-bundles.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,13 @@ define void @func(ptr %P, i32 %P1, ptr %P2, ptr %P3) {
2828
call void @llvm.assume(i1 true) ["separate_storage"(ptr %P)]
2929
; CHECK: arguments to separate_storage assumptions should be pointers
3030
call void @llvm.assume(i1 true) ["separate_storage"(ptr %P, i32 123)]
31+
; CHECK: range assumptions should have 3 arguments
32+
call void @llvm.assume(i1 true) ["range"(i32 %P1, i32 0)]
33+
; CHECK: first argument should be an integer or vector of integers
34+
call void @llvm.assume(i1 true) ["range"(ptr %P, i32 %P1, i32 4)]
35+
; CHECK: second argument should be an integer with same bit width as the first argument
36+
call void @llvm.assume(i1 true) ["range"(i32 %P1, ptr %P, i32 4)]
37+
; CHECK: third argument should be an integer with same bit width as the first argument
38+
call void @llvm.assume(i1 true) ["range"(i32 %P1, i32 4, i8 10)]
3139
ret void
3240
}

llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,10 @@ static void RunRandTest(uint64_t Seed, int Size, int MinCount, int MaxCount,
411411
std::mt19937 Rng(Seed);
412412
std::uniform_int_distribution<int> DistCount(MinCount, MaxCount);
413413
std::uniform_int_distribution<unsigned> DistValue(0, MaxValue);
414-
std::uniform_int_distribution<unsigned> DistAttr(0,
415-
Attribute::EndAttrKinds - 1);
414+
std::uniform_int_distribution<unsigned> DistEnumAttr(Attribute::FirstEnumAttr,
415+
Attribute::LastEnumAttr);
416+
std::uniform_int_distribution<unsigned> DistIntAttr(Attribute::FirstIntAttr,
417+
Attribute::LastIntAttr);
416418

417419
std::unique_ptr<Module> Mod = std::make_unique<Module>("AssumeQueryAPI", C);
418420
if (!Mod)
@@ -449,7 +451,7 @@ static void RunRandTest(uint64_t Seed, int Size, int MinCount, int MaxCount,
449451
for (int i = 0; i < Size; i++) {
450452
int count = DistCount(Rng);
451453
int value = DistValue(Rng);
452-
int attr = DistAttr(Rng);
454+
int attr = count > 1 ? DistIntAttr(Rng) : DistEnumAttr(Rng);
453455
std::string str;
454456
raw_string_ostream ss(str);
455457
ss << Attribute::getNameFromAttrKind(

0 commit comments

Comments
 (0)