Skip to content

Commit 393be12

Browse files
committed
[Attributor] Look at base values for align, nonnull, and deref
Stripping bitcasts and 0-geps helps normalization and minimizes the impact of a follow up change.
1 parent cb8adf7 commit 393be12

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,7 @@ struct AANonNullImpl : AANonNull {
23652365

23662366
/// See AbstractAttribute::initialize(...).
23672367
void initialize(Attributor &A) override {
2368-
Value &V = getAssociatedValue();
2368+
Value &V = *getAssociatedValue().stripPointerCasts();
23692369
if (!NullIsDefined &&
23702370
hasAttr({Attribute::NonNull, Attribute::Dereferenceable},
23712371
/* IgnoreSubsumingPositions */ false, &A)) {
@@ -2389,7 +2389,7 @@ struct AANonNullImpl : AANonNull {
23892389
}
23902390
}
23912391

2392-
if (isa<GlobalValue>(&getAssociatedValue())) {
2392+
if (isa<GlobalValue>(V)) {
23932393
indicatePessimisticFixpoint();
23942394
return;
23952395
}
@@ -4217,6 +4217,7 @@ struct AADereferenceableImpl : AADereferenceable {
42174217

42184218
/// See AbstractAttribute::initialize(...).
42194219
void initialize(Attributor &A) override {
4220+
Value &V = *getAssociatedValue().stripPointerCasts();
42204221
SmallVector<Attribute, 4> Attrs;
42214222
getAttrs({Attribute::Dereferenceable, Attribute::DereferenceableOrNull},
42224223
Attrs, /* IgnoreSubsumingPositions */ false, &A);
@@ -4227,9 +4228,8 @@ struct AADereferenceableImpl : AADereferenceable {
42274228
NonNullAA = &A.getAAFor<AANonNull>(*this, IRP, DepClassTy::NONE);
42284229

42294230
bool CanBeNull, CanBeFreed;
4230-
takeKnownDerefBytesMaximum(
4231-
IRP.getAssociatedValue().getPointerDereferenceableBytes(
4232-
A.getDataLayout(), CanBeNull, CanBeFreed));
4231+
takeKnownDerefBytesMaximum(V.getPointerDereferenceableBytes(
4232+
A.getDataLayout(), CanBeNull, CanBeFreed));
42334233

42344234
bool IsFnInterface = IRP.isFnInterfaceKind();
42354235
Function *FnScope = IRP.getAnchorScope();
@@ -4520,7 +4520,7 @@ struct AAAlignImpl : AAAlign {
45204520
for (const Attribute &Attr : Attrs)
45214521
takeKnownMaximum(Attr.getValueAsInt());
45224522

4523-
Value &V = getAssociatedValue();
4523+
Value &V = *getAssociatedValue().stripPointerCasts();
45244524
takeKnownMaximum(V.getPointerAlignment(A.getDataLayout()).value());
45254525

45264526
if (getIRPosition().isFnInterfaceKind() &&

llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ define void @local_alloca_simplifiable_2() {
608608
; IS__CGSCC_OPM-NEXT: br label [[FOR_COND28]], !llvm.loop [[LOOP23:![0-9]+]]
609609
; IS__CGSCC_OPM: for.end38:
610610
; IS__CGSCC_OPM-NEXT: [[I24:%.*]] = getelementptr inbounds [1024 x i8], [1024 x i8]* [[BYTES]], i64 0, i64 0
611-
; IS__CGSCC_OPM-NEXT: call void @llvm.lifetime.end.p0i8(i64 noundef 1024, i8* nofree noundef nonnull [[I24]])
611+
; IS__CGSCC_OPM-NEXT: call void @llvm.lifetime.end.p0i8(i64 noundef 1024, i8* nofree noundef nonnull align 16 dereferenceable(1024) [[I24]])
612612
; IS__CGSCC_OPM-NEXT: ret void
613613
;
614614
; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@local_alloca_simplifiable_2() {
@@ -691,7 +691,7 @@ define void @local_alloca_simplifiable_2() {
691691
; IS__CGSCC_NPM-NEXT: br label [[FOR_COND28]], !llvm.loop [[LOOP23:![0-9]+]]
692692
; IS__CGSCC_NPM: for.end38:
693693
; IS__CGSCC_NPM-NEXT: [[I24:%.*]] = getelementptr inbounds [1024 x i8], [1024 x i8]* [[BYTES]], i64 0, i64 0
694-
; IS__CGSCC_NPM-NEXT: call void @llvm.lifetime.end.p0i8(i64 noundef 1024, i8* nofree noundef nonnull [[I24]])
694+
; IS__CGSCC_NPM-NEXT: call void @llvm.lifetime.end.p0i8(i64 noundef 1024, i8* nofree noundef nonnull align 16 dereferenceable(1024) [[I24]])
695695
; IS__CGSCC_NPM-NEXT: ret void
696696
;
697697
entry:

0 commit comments

Comments
 (0)