Skip to content

Commit e095a93

Browse files
committed
Incorporated feedback
1 parent fc269c1 commit e095a93

File tree

4 files changed

+268
-226
lines changed

4 files changed

+268
-226
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6298,6 +6298,7 @@ struct AAInvariantLoadPointer : public AbstractAttribute {
62986298
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) {
62996299
if (!IRP.getAssociatedType()->isPointerTy())
63006300
return false;
6301+
63016302
return AbstractAttribute::isValidIRPositionForInit(A, IRP);
63026303
}
63036304

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12579,7 +12579,7 @@ struct AAInvariantLoadPointerImpl
1257912579

1258012580
ChangeStatus updateImpl(Attributor &A) override {
1258112581
if (isKnownInvariant())
12582-
return ChangeStatus::UNCHANGED;
12582+
return indicateOptimisticFixpoint();
1258312583

1258412584
ChangeStatus Changed = ChangeStatus::UNCHANGED;
1258512585

@@ -12605,15 +12605,13 @@ struct AAInvariantLoadPointerImpl
1260512605
const auto *AUO = A.getOrCreateAAFor<AAUnderlyingObjects>(
1260612606
getIRPosition(), this, DepClassTy::REQUIRED);
1260712607

12608-
if (!AUO->forallUnderlyingObjects(IsInvariantLoadIfPointer)) {
12609-
removeAssumedBits(IS_INVARIANT);
12610-
return ChangeStatus::CHANGED;
12611-
}
12608+
if (!AUO->forallUnderlyingObjects(IsInvariantLoadIfPointer))
12609+
return indicatePessimisticFixpoint();
1261212610

1261312611
if (!UsedAssumedInformation) {
1261412612
// pointer is known (not assumed) to be invariant
1261512613
addKnownBits(IS_INVARIANT);
12616-
return ChangeStatus::CHANGED;
12614+
return indicateOptimisticFixpoint() | Changed;
1261712615
}
1261812616

1261912617
return Changed;
@@ -12671,53 +12669,90 @@ struct AAInvariantLoadPointerImpl
1267112669
if (isKnown(IS_NOALIAS) || !isAssumed(IS_NOALIAS))
1267212670
return ChangeStatus::UNCHANGED;
1267312671

12674-
const auto *ANoAlias = A.getOrCreateAAFor<AANoAlias>(getIRPosition(), this,
12675-
DepClassTy::REQUIRED);
12676-
if (!ANoAlias)
12677-
return tryInferNoAlias(A);
12672+
const auto *F = getAssociatedFunction();
1267812673

12679-
if (!ANoAlias->isAssumedNoAlias()) {
12674+
if (F && isCallableCC(F->getCallingConv())) {
12675+
// program-wide alias information cannot be inferred
1268012676
removeAssumedBits(IS_NOALIAS);
1268112677
return ChangeStatus::CHANGED;
1268212678
}
12683-
if (ANoAlias->isKnownNoAlias())
12684-
addKnownBits(IS_NOALIAS);
1268512679

12686-
return ChangeStatus::UNCHANGED;
12687-
}
12680+
// try to use AANoAlias
12681+
if (const auto *ANoAlias = A.getOrCreateAAFor<AANoAlias>(
12682+
getIRPosition(), this, DepClassTy::REQUIRED)) {
12683+
if (ANoAlias->isKnownNoAlias()) {
12684+
addKnownBits(IS_NOALIAS);
12685+
return ChangeStatus::UNCHANGED;
12686+
}
12687+
12688+
if (!ANoAlias->isAssumedNoAlias()) {
12689+
removeAssumedBits(IS_NOALIAS);
12690+
return ChangeStatus::CHANGED;
12691+
}
12692+
12693+
return ChangeStatus::UNCHANGED;
12694+
}
12695+
12696+
// if the function is not callable, try to infer noalias from argument
12697+
// attribute, since it is applicable for the duration of the function
12698+
if (const auto *Arg = getAssociatedArgument()) {
12699+
if (Arg->hasNoAliasAttr()) {
12700+
addKnownBits(IS_NOALIAS);
12701+
return ChangeStatus::UNCHANGED;
12702+
}
12703+
12704+
// noalias information is not provided, and cannot be inferred,
12705+
// so we conservatively assume the pointer aliases.
12706+
removeAssumedBits(IS_NOALIAS);
12707+
return ChangeStatus::CHANGED;
12708+
}
1268812709

12689-
/// Fallback method if updateNoAlias fails to infer noalias information from
12690-
/// AANoAlias.
12691-
virtual ChangeStatus tryInferNoAlias(Attributor &A) {
1269212710
return ChangeStatus::UNCHANGED;
1269312711
}
1269412712

1269512713
ChangeStatus updateReadOnly(Attributor &A) {
1269612714
if (isKnown(IS_READONLY) || !isAssumed(IS_READONLY))
1269712715
return ChangeStatus::UNCHANGED;
1269812716

12699-
// AAMemoryBehavior may crash if value is global
12700-
if (!getAssociatedFunction())
12701-
return tryInferReadOnly(A);
12717+
const auto *F = getAssociatedFunction();
1270212718

12703-
const auto *AMemoryBehavior = A.getOrCreateAAFor<AAMemoryBehavior>(
12704-
getIRPosition(), this, DepClassTy::REQUIRED);
12705-
if (!AMemoryBehavior)
12706-
return tryInferReadOnly(A);
12719+
if (!F)
12720+
return ChangeStatus::UNCHANGED;
1270712721

12708-
if (!AMemoryBehavior->isAssumedReadOnly()) {
12722+
if (isCallableCC(F->getCallingConv())) {
12723+
// readonly attribute is only useful if applicable program-wide
1270912724
removeAssumedBits(IS_READONLY);
1271012725
return ChangeStatus::CHANGED;
1271112726
}
12712-
if (AMemoryBehavior->isKnownReadOnly())
12713-
addKnownBits(IS_READONLY);
1271412727

12715-
return ChangeStatus::UNCHANGED;
12716-
}
12728+
// try to use AAMemoryBehavior to infer readonly attribute
12729+
if (const auto *AMemoryBehavior = A.getOrCreateAAFor<AAMemoryBehavior>(
12730+
getIRPosition(), this, DepClassTy::REQUIRED)) {
12731+
if (!AMemoryBehavior->isAssumedReadOnly()) {
12732+
removeAssumedBits(IS_READONLY);
12733+
return ChangeStatus::CHANGED;
12734+
}
12735+
12736+
if (AMemoryBehavior->isKnownReadOnly()) {
12737+
addKnownBits(IS_READONLY);
12738+
return ChangeStatus::UNCHANGED;
12739+
}
12740+
12741+
return ChangeStatus::UNCHANGED;
12742+
}
12743+
12744+
if (const auto *Arg = getAssociatedArgument()) {
12745+
if (Arg->onlyReadsMemory()) {
12746+
addKnownBits(IS_READONLY);
12747+
return ChangeStatus::UNCHANGED;
12748+
}
12749+
12750+
// readonly information is not provided, and cannot be inferred from
12751+
// AAMemoryBehavior
12752+
removeAssumedBits(IS_READONLY);
12753+
return ChangeStatus::CHANGED;
12754+
}
1271712755

12718-
/// Fallback method if updateReadOnly fails to infer readonly information from
12719-
/// AAMemoryBehavior.
12720-
virtual ChangeStatus tryInferReadOnly(Attributor &A) {
1272112756
return ChangeStatus::UNCHANGED;
1272212757
}
1272312758
};
@@ -12741,33 +12776,6 @@ struct AAInvariantLoadPointerCallSiteReturned final
1274112776
struct AAInvariantLoadPointerArgument final : AAInvariantLoadPointerImpl {
1274212777
AAInvariantLoadPointerArgument(const IRPosition &IRP, Attributor &A)
1274312778
: AAInvariantLoadPointerImpl(IRP, A) {}
12744-
12745-
protected:
12746-
ChangeStatus tryInferNoAlias(Attributor &A) override {
12747-
const auto *Arg = getAssociatedArgument();
12748-
if (Arg->hasNoAliasAttr()) {
12749-
addKnownBits(IS_NOALIAS);
12750-
return ChangeStatus::UNCHANGED;
12751-
}
12752-
12753-
// noalias information is not provided, and cannot be inferred from
12754-
// AANoAlias
12755-
removeAssumedBits(IS_NOALIAS);
12756-
return ChangeStatus::CHANGED;
12757-
}
12758-
12759-
ChangeStatus tryInferReadOnly(Attributor &A) override {
12760-
const auto *Arg = getAssociatedArgument();
12761-
if (Arg->onlyReadsMemory()) {
12762-
addKnownBits(IS_READONLY);
12763-
return ChangeStatus::UNCHANGED;
12764-
}
12765-
12766-
// readonly information is not provided, and cannot be inferred from
12767-
// AAMemoryBehavior
12768-
removeAssumedBits(IS_READONLY);
12769-
return ChangeStatus::CHANGED;
12770-
}
1277112779
};
1277212780

1277312781
struct AAInvariantLoadPointerCallSiteArgument final

llvm/test/Transforms/Attributor/multiple-offsets-pointer-info.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define i8 @select_offsets_simplifiable_1(i1 %cnd1, i1 %cnd2) {
1010
; CHECK-LABEL: define {{[^@]+}}@select_offsets_simplifiable_1
1111
; CHECK-SAME: (i1 [[CND1:%.*]], i1 [[CND2:%.*]]) {
1212
; CHECK-NEXT: entry:
13-
; CHECK-NEXT: [[BYTES:%.*]] = call noalias ptr @calloc(i64 noundef 1024, i64 noundef 1)
13+
; CHECK-NEXT: [[BYTES:%.*]] = call ptr @calloc(i64 noundef 1024, i64 noundef 1)
1414
; CHECK-NEXT: [[GEP23:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 23
1515
; CHECK-NEXT: store i8 23, ptr [[GEP23]], align 4
1616
; CHECK-NEXT: [[GEP29:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 29
@@ -190,7 +190,7 @@ define i8 @select_offsets_not_simplifiable_3(i1 %cnd1, i1 %cnd2) {
190190
; CHECK-LABEL: define {{[^@]+}}@select_offsets_not_simplifiable_3
191191
; CHECK-SAME: (i1 [[CND1:%.*]], i1 [[CND2:%.*]]) {
192192
; CHECK-NEXT: entry:
193-
; CHECK-NEXT: [[BYTES:%.*]] = call noalias ptr @calloc(i64 noundef 1024, i64 noundef 1)
193+
; CHECK-NEXT: [[BYTES:%.*]] = call ptr @calloc(i64 noundef 1024, i64 noundef 1)
194194
; CHECK-NEXT: [[SEL0:%.*]] = select i1 [[CND1]], i64 23, i64 29
195195
; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[CND2]], i64 [[SEL0]], i64 7
196196
; CHECK-NEXT: [[GEP_SEL:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 [[SEL1]]
@@ -214,7 +214,7 @@ define i8 @select_offsets_not_simplifiable_4(i1 %cnd1, i1 %cnd2) {
214214
; CHECK-LABEL: define {{[^@]+}}@select_offsets_not_simplifiable_4
215215
; CHECK-SAME: (i1 [[CND1:%.*]], i1 [[CND2:%.*]]) {
216216
; CHECK-NEXT: entry:
217-
; CHECK-NEXT: [[BYTES:%.*]] = call noalias ptr @calloc(i64 noundef 1024, i64 noundef 1)
217+
; CHECK-NEXT: [[BYTES:%.*]] = call ptr @calloc(i64 noundef 1024, i64 noundef 1)
218218
; CHECK-NEXT: [[SEL0:%.*]] = select i1 [[CND1]], i64 23, i64 29
219219
; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[CND2]], i64 [[SEL0]], i64 7
220220
; CHECK-NEXT: [[GEP_SEL:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 [[SEL1]]
@@ -445,7 +445,7 @@ define i8 @phi_gep_not_simplifiable_2(i1 %cnd1, i1 %cnd2) {
445445
; CHECK-LABEL: define {{[^@]+}}@phi_gep_not_simplifiable_2
446446
; CHECK-SAME: (i1 [[CND1:%.*]], i1 [[CND2:%.*]]) {
447447
; CHECK-NEXT: entry:
448-
; CHECK-NEXT: [[BYTES:%.*]] = call noalias ptr @calloc(i64 noundef 1024, i64 noundef 1)
448+
; CHECK-NEXT: [[BYTES:%.*]] = call ptr @calloc(i64 noundef 1024, i64 noundef 1)
449449
; CHECK-NEXT: [[GEP23:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 23
450450
; CHECK-NEXT: br i1 [[CND1]], label [[THEN:%.*]], label [[ELSE:%.*]]
451451
; CHECK: then:

0 commit comments

Comments
 (0)