Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ActivityAnalysis] Remove isConstantValue call in activity analysis #1608

Merged
merged 32 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
12de271
Remove cop2
rmoyard Jan 11, 2024
534537b
Merge branch 'main' into fix_analysis
rmoyard Jan 22, 2024
850a5c1
Merge branch 'main' into fix_analysis
rmoyard Feb 5, 2024
767b7d4
Add integration test
rmoyard Feb 5, 2024
9de9fa7
Add test
rmoyard Feb 5, 2024
349d67c
merge conflict
rmoyard Feb 5, 2024
3f6d7f1
Update enzyme/test/ActivityAnalysis/integration.ll
rmoyard Feb 5, 2024
0c0e9dd
Update test
rmoyard Feb 6, 2024
866e095
Update test
rmoyard Feb 6, 2024
4d9a642
Merge branch 'main' into fix_analysis
rmoyard Feb 6, 2024
c416b2f
Merge branch 'main' into fix_analysis
rmoyard Feb 8, 2024
e13767a
Update test
rmoyard Feb 14, 2024
64369fc
Merge branch 'main' into fix_analysis
rmoyard Feb 14, 2024
4e2a53c
Add missing return
rmoyard Feb 14, 2024
34a940b
Merge branch 'fix_analysis' of https://github.com/rmoyard/Enzyme into…
rmoyard Feb 14, 2024
d75741d
Merge branch 'main' into fix_analysis
rmoyard Feb 14, 2024
b7dfd22
Format and test
rmoyard Feb 15, 2024
d5c3f18
Back gt
rmoyard Feb 15, 2024
469d29b
Merge branch 'fix_analysis' of https://github.com/rmoyard/Enzyme into…
rmoyard Feb 15, 2024
cb449a3
Test fix trial
rmoyard Feb 16, 2024
ddbad85
Lower test llvm to 15
rmoyard Feb 16, 2024
1ea2acd
Merge branch 'main' into fix_analysis
rmoyard Feb 16, 2024
a0c4456
Merge branch 'main' into fix_analysis
rmoyard Feb 16, 2024
dd02508
Update enzyme/test/ActivityAnalysis/integration.ll
rmoyard Feb 16, 2024
d560062
Update activity printer for opaque type
rmoyard Feb 17, 2024
a2ce362
Merge branch 'fix_analysis' of https://github.com/rmoyard/Enzyme into…
rmoyard Feb 17, 2024
87efd97
update ->
rmoyard Feb 17, 2024
8919afd
Update activity analysis
rmoyard Feb 17, 2024
c88b9f4
Update if/elif llvm
rmoyard Feb 17, 2024
cada4fe
Update llvm versioning
rmoyard Feb 20, 2024
311e708
Merge branch 'main' into fix_analysis
rmoyard Feb 20, 2024
3a89c7d
Merge branch 'main' into fix_analysis
rmoyard Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions enzyme/Enzyme/ActivityAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2071,14 +2071,14 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
<< "\n";
if (auto SI = dyn_cast<StoreInst>(I)) {
bool cop = !Hypothesis->isConstantValue(TR, SI->getValueOperand());
bool cop2 = !Hypothesis->isConstantValue(TR, SI->getPointerOperand());
// bool cop2 = !Hypothesis->isConstantValue(TR,
// SI->getPointerOperand());
if (EnzymePrintActivity)
llvm::errs() << " -- store potential activity: " << (int)cop << ","
<< (int)cop2 << ","
llvm::errs() << " -- store potential activity: " << (int)cop
<< " - " << *SI << " of "
<< " Val=" << *Val << "\n";
potentialStore = I;
if (cop && cop2)
if (cop) // && cop2)
potentiallyActiveStore = SI;
} else if (auto MTI = dyn_cast<MemTransferInst>(I)) {
bool cop = !Hypothesis->isConstantValue(TR, MTI->getArgOperand(1));
Expand Down
93 changes: 93 additions & 0 deletions enzyme/test/ActivityAnalysis/integration.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
; RUN: if [ %llvmver -gt 15 ]; then %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s; fi
rmoyard marked this conversation as resolved.
Show resolved Hide resolved
rmoyard marked this conversation as resolved.
Show resolved Hide resolved

declare void @free(ptr)

declare ptr @malloc(i64)

; This function just returns 2*input, its derivate should be 2.0.
define void @f.preprocess(ptr %param, i64 %mallocsize, ptr %res) {

; arithmetic block, changing anything here makes the bug go away
%buffer1 = call ptr @malloc(i64 %mallocsize)
%tmp = call ptr @malloc(i64 72)
%ptrtoint = ptrtoint ptr %tmp to i64
%and = and i64 %ptrtoint, -64
%inttoptr = inttoptr i64 %and to ptr
%loadarg = load double, ptr %param
%storedargmul = fmul double %loadarg, 4.000000e+00
store double %storedargmul, ptr %inttoptr
call void @free(ptr %tmp)
store double %storedargmul, ptr %buffer1

; prep arg 0 by setting the aligned pointer to the input
%arg0 = alloca { ptr, ptr, i64 }
%arg0_aligned = getelementptr inbounds { ptr, ptr, i64 }, ptr %arg0, i64 0, i32 1
store ptr %param, ptr %arg0_aligned

; prep arg 1 by setting the aligned pointer to buffer1
%arg1 = alloca { ptr, ptr, i64, [1 x i64], [1 x i64] }
%arg1_aligned = getelementptr inbounds { ptr, ptr, i64, [1 x i64], [1 x i64] }, ptr %arg1, i64 0, i32 1
store ptr %buffer1, ptr %arg1_aligned

; prep arg 2 by setting the aligned pointer to buffer2
%arg2 = alloca { ptr, ptr, i64 }
%arg2_aligned = getelementptr inbounds { ptr, ptr, i64 }, ptr %arg2, i64 0, i32 1
%buffer2 = call ptr @malloc(i64 8)
store ptr %buffer2, ptr %arg2_aligned

; nested call, required for bug
call void @nested(ptr %arg0, ptr %arg1, ptr %arg2)

; return a result from this function, needs to be positioned after arithmetic block for bug
%x = load double, ptr %param
%y = fmul double %x, 2.0
store double %y, ptr %res

ret void
}

; Identity function, 2nd argument required for bug (but not used)
define void @nested(ptr %arg0, ptr %arg1, ptr %arg2) {

; load aligned pointer from %arg0 & load argument value
%loadarg = load { ptr, ptr, i64 }, ptr %arg0
%extractarg = extractvalue { ptr, ptr, i64 } %loadarg, 1
%loadextractarg = load double, ptr %extractarg

; load aligned pointer from %arg2 & store result value
%loadarg2 = load { ptr, ptr, i64 }, ptr %arg2
%extractarg2 = extractvalue { ptr, ptr, i64 } %loadarg2, 1
store double %loadextractarg, ptr %extractarg2

ret void
}

; CHECK: ptr %param: icv:0
; CHECK-NEXT: i64 %mallocsize: icv:1
; CHECK-NEXT: ptr %res: icv:0

; CHECK: %buffer1 = call ptr @malloc(i64 %mallocsize): icv:0 ici:1
; CHECK-NEXT: %tmp = call ptr @malloc(i64 72): icv:1 ici:1
; CHECK-NEXT: %ptrtoint = ptrtoint ptr %tmp to i64: icv:1 ici:1
; CHECK-NEXT: %and = and i64 %ptrtoint, -64: icv:1 ici:1
; CHECK-NEXT: %inttoptr = inttoptr i64 %and to ptr: icv:1 ici:1
; CHECK-NEXT: %loadarg = load double, ptr %param, align 8: icv:0 ici:0
; CHECK-NEXT: %storedargmul = fmul double %loadarg, 4.000000e+00: icv:0 ici:0
; CHECK-NEXT: store double %storedargmul, ptr %inttoptr, align 8: icv:1 ici:1
; CHECK-NEXT: call void @free(ptr %tmp): icv:1 ici:1
; CHECK-NEXT: store double %storedargmul, ptr %buffer1, align 8: icv:1 ici:0
; CHECK-NEXT: %arg0 = alloca { ptr, ptr, i64 }, align 8: icv:0 ici:1
; CHECK-NEXT: %arg0_aligned = getelementptr inbounds { ptr, ptr, i64 }, ptr %arg0, i64 0, i32 1: icv:0 ici:1
; CHECK-NEXT: store ptr %param, ptr %arg0_aligned, align 8: icv:1 ici:0
; CHECK-NEXT: %arg1 = alloca { ptr, ptr, i64, [1 x i64], [1 x i64] }, align 8: icv:0 ici:1
; CHECK-NEXT: %arg1_aligned = getelementptr inbounds { ptr, ptr, i64, [1 x i64], [1 x i64] }, ptr %arg1, i64 0, i32 1: icv:0 ici:1
; CHECK-NEXT: store ptr %buffer1, ptr %arg1_aligned, align 8: icv:1 ici:0
; CHECK-NEXT: %arg2 = alloca { ptr, ptr, i64 }, align 8: icv:0 ici:1
; CHECK-NEXT: %arg2_aligned = getelementptr inbounds { ptr, ptr, i64 }, ptr %arg2, i64 0, i32 1: icv:0 ici:1
; CHECK-NEXT: %buffer2 = call ptr @malloc(i64 8): icv:0 ici:1
; CHECK-NEXT: store ptr %buffer2, ptr %arg2_aligned, align 8: icv:1 ici:0
; CHECK-NEXT: call void @nested(ptr %arg0, ptr %arg1, ptr %arg2): icv:1 ici:0
; CHECK-NEXT: %x = load double, ptr %param, align 8: icv:0 ici:0
; CHECK-NEXT: %y = fmul double %x, 2.000000e+00: icv:0 ici:0
; CHECK-NEXT: store double %y, ptr %res, align 8: icv:1 ici:0
; CHECK-NEXT: ret void: icv:1 ici:1
Loading