Skip to content

Commit

Permalink
More noalias optimizations (#2161)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Nov 11, 2024
1 parent f8a4892 commit 4a0ebd8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions enzyme/Enzyme/JLInstSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,31 @@ bool jlInstSimplify(llvm::Function &F, TargetLibraryInfo &TLI,
changed = true;
continue;
}

{
bool noalias_from_capture = false;
for (int i = 0; i < 2; i++) {
Value *start = (i == 0) ? lhs : rhs;
Value *end = (i == 0) ? rhs : lhs;
if (isNoAlias(start)) {
if (auto endi = dyn_cast<Instruction>(end)) {
if (notCapturedBefore(start, endi)) {
noalias_from_capture = true;
break;
}
}
}
}
if (noalias_from_capture) {
auto repval = ICmpInst::isTrueWhenEqual(pred)
? ConstantInt::get(I.getType(), 0)
: ConstantInt::get(I.getType(), 1);
I.replaceAllUsesWith(repval);
changed = true;
continue;
}
}

auto llhs = dyn_cast<LoadInst>(lhs);
auto lrhs = dyn_cast<LoadInst>(rhs);
if (llhs && lrhs && isa<PointerType>(llhs->getType()) &&
Expand Down
25 changes: 25 additions & 0 deletions enzyme/test/Enzyme/JLSimplify/alloc2d.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; RUN: if [ %llvmver -lt 16 ]; then %opt < %s %loadEnzyme -jl-inst-simplify -S | FileCheck %s; fi
; RUN: %opt < %s %newLoadEnzyme -passes="jl-inst-simplify" -S | FileCheck %s

declare noalias nonnull {} addrspace(10)* @ijl_alloc_array_2d({} addrspace(10)*, i64, i64) local_unnamed_addr #0

declare fastcc nonnull {} addrspace(10)* @a20()

define i1 @chillin() {
bb:
%i = call fastcc nonnull {} addrspace(10)* @a20()
%i2 = call noalias nonnull {} addrspace(10)* @ijl_alloc_array_2d({} addrspace(10)* addrspacecast ({}* inttoptr (i64 139753406594768 to {}*) to {} addrspace(10)*), i64 5, i64 6)
%i3 = icmp eq {} addrspace(10)* %i2, %i
ret i1 %i3
}

attributes #0 = { inaccessiblememonly mustprogress nofree nounwind willreturn }


; CHECK: define i1 @chillin() {
; CHECK-NEXT: bb:
; CHECK-NEXT: %i = call fastcc nonnull {} addrspace(10)* @a20()
; CHECK-NEXT: %i2 = call noalias nonnull {} addrspace(10)* @ijl_alloc_array_2d({} addrspace(10)* addrspacecast ({}* inttoptr (i64 139753406594768 to {}*) to {} addrspace(10)*), i64 5, i64 6)
; CHECK-NEXT: %i3 = icmp eq {} addrspace(10)* %i2, %i
; CHECK-NEXT: ret i1 false
; CHECK-NEXT: }

0 comments on commit 4a0ebd8

Please sign in to comment.