Skip to content

Commit 8abd69a

Browse files
committed
[Attributor] Bail early if AAMemoryLocation cannot derive anything
Before this change we looked through all memory operations in a function even if the first was an unknown call that could do anything. This did cost a lot of time but there is little use to do so. We also avoid creating AAs for things that we would have looked at in case no other AA will; that is the reason for the test changes. Running only the attributor-cgscc pass on a IR version of `llvm-test-suite/MultiSource/Applications/SPASS/clause.c` reduced the time we spend in `AAMemoryLocation::update` from 4% total to 0.9% (disclaimer: no accurate measurements).
1 parent 1d99c3d commit 8abd69a

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6628,7 +6628,9 @@ struct AAMemoryLocationFunction final : public AAMemoryLocationImpl {
66286628
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Accessed locations for " << I
66296629
<< ": " << getMemoryLocationsAsStr(MLK) << "\n");
66306630
removeAssumedBits(inverseLocation(MLK, false, false));
6631-
return true;
6631+
// Stop once only the valid bit set in the *not assumed location*, thus
6632+
// once we don't actually exclude any memory locations in the state.
6633+
return getAssumedNotAccessedLocation() != VALID_STATE;
66326634
};
66336635

66346636
if (!A.checkForAllReadWriteInstructions(CheckRWInst, *this))

llvm/test/Transforms/Attributor/dereferenceable-1.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ define void @f7_2(i1 %c) {
280280
; CHECK-SAME: (i1 [[C:%.*]])
281281
; CHECK-NEXT: [[PTR:%.*]] = tail call nonnull align 4 dereferenceable(4) i32* @unkown_ptr()
282282
; CHECK-NEXT: [[A:%.*]] = tail call i32 @unkown_f(i32* nonnull align 4 dereferenceable(4) [[PTR]])
283+
; CHECK-NEXT: [[ARG_A_0:%.*]] = load i32, i32* [[PTR]], align 4
283284
; CHECK-NEXT: [[B:%.*]] = tail call i32 @unkown_f(i32* nonnull align 4 dereferenceable(4) [[PTR]])
284285
; CHECK-NEXT: br i1 [[C]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
285286
; CHECK: if.true:

llvm/test/Transforms/Attributor/heap_to_stack.ll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,11 @@ define i32 @irreducible_cfg(i32 %0) {
450450
; IS________OPM-NEXT: [[TMP14]] = add nsw i32 [[DOT1]], 1
451451
; IS________OPM-NEXT: br label [[TMP8]]
452452
; IS________OPM: 15:
453-
; IS________OPM-NEXT: [[TMP16:%.*]] = bitcast i32* [[TMP3]] to i8*
454-
; IS________OPM-NEXT: call void @free(i8* nocapture [[TMP16]])
455-
; IS________OPM-NEXT: [[TMP17:%.*]] = load i32, i32* [[TMP3]], align 4
456-
; IS________OPM-NEXT: ret i32 [[TMP17]]
453+
; IS________OPM-NEXT: [[TMP16:%.*]] = load i32, i32* [[TMP3]], align 4
454+
; IS________OPM-NEXT: [[TMP17:%.*]] = bitcast i32* [[TMP3]] to i8*
455+
; IS________OPM-NEXT: call void @free(i8* nocapture [[TMP17]])
456+
; IS________OPM-NEXT: [[TMP18:%.*]] = load i32, i32* [[TMP3]], align 4
457+
; IS________OPM-NEXT: ret i32 [[TMP18]]
457458
;
458459
; IS________NPM-LABEL: define {{[^@]+}}@irreducible_cfg
459460
; IS________NPM-SAME: (i32 [[TMP0:%.*]])

llvm/test/Transforms/Attributor/liveness.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ define i32 @main() {
19201920
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[G_0]], 1
19211921
; CHECK-NEXT: br label [[FOR_COND_0]]
19221922
; CHECK: for.end.0:
1923-
; CHECK-NEXT: [[CALL:%.*]] = call noalias i8* @malloc(i64 8)
1923+
; CHECK-NEXT: [[CALL:%.*]] = call i8* @malloc(i64 8)
19241924
; CHECK-NEXT: store i8* [[CALL]], i8** bitcast (%struct.a** @e to i8**), align 8
19251925
; CHECK-NEXT: [[B:%.*]] = bitcast i8* [[CALL]] to %struct.a**
19261926
; CHECK-NEXT: store %struct.a* null, %struct.a** [[B]], align 8

llvm/test/Transforms/Attributor/noreturn_async.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes --check-attributes
2-
; RUN: opt -attributor -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s
2+
; RUN: opt -attributor -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=1 -S < %s | FileCheck %s
33
;
44
; This file is the same as noreturn_sync.ll but with a personality which
55
; indicates that the exception handler *can* catch asynchronous exceptions. As

0 commit comments

Comments
 (0)