From 12de271955aaaa2eceacd482d6a30a5186d7846a Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Thu, 11 Jan 2024 15:39:43 -0500 Subject: [PATCH 01/17] Remove cop2 --- enzyme/Enzyme/ActivityAnalysis.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/enzyme/Enzyme/ActivityAnalysis.cpp b/enzyme/Enzyme/ActivityAnalysis.cpp index 245be4a2958c..fe92c3433f48 100644 --- a/enzyme/Enzyme/ActivityAnalysis.cpp +++ b/enzyme/Enzyme/ActivityAnalysis.cpp @@ -2106,14 +2106,14 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) { << "\n"; if (auto SI = dyn_cast(I)) { bool cop = !Hypothesis->isConstantValue(TR, SI->getValueOperand()); - bool cop2 = !Hypothesis->isConstantValue(TR, SI->getPointerOperand()); - if (EnzymePrintActivity) - llvm::errs() << " -- store potential activity: " << (int)cop << "," - << (int)cop2 << "," - << " - " << *SI << " of " - << " Val=" << *Val << "\n"; + // bool cop2 = !Hypothesis->isConstantValue(TR, SI->getPointerOperand()); + // if (EnzymePrintActivity) + // llvm::errs() << " -- store potential activity: " << (int)cop << "," + // << (int)cop2 << "," + // << " - " << *SI << " of " + // << " Val=" << *Val << "\n"; potentialStore = I; - if (cop && cop2) + if (cop)// && cop2) potentiallyActiveStore = SI; } else if (auto MTI = dyn_cast(I)) { bool cop = !Hypothesis->isConstantValue(TR, MTI->getArgOperand(1)); From 767b7d4e97298e42ff86d813853bb4c7169c4594 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Mon, 5 Feb 2024 11:04:59 -0500 Subject: [PATCH 02/17] Add integration test --- enzyme/Enzyme/ActivityAnalysis.cpp | 11 +-- enzyme/test/ActivityAnalysis/integration.ll | 103 ++++++++++++++++++++ 2 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 enzyme/test/ActivityAnalysis/integration.ll diff --git a/enzyme/Enzyme/ActivityAnalysis.cpp b/enzyme/Enzyme/ActivityAnalysis.cpp index fe92c3433f48..e81202cf93c8 100644 --- a/enzyme/Enzyme/ActivityAnalysis.cpp +++ b/enzyme/Enzyme/ActivityAnalysis.cpp @@ -2107,13 +2107,12 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) { if (auto SI = dyn_cast(I)) { bool cop = !Hypothesis->isConstantValue(TR, SI->getValueOperand()); // bool cop2 = !Hypothesis->isConstantValue(TR, SI->getPointerOperand()); - // if (EnzymePrintActivity) - // llvm::errs() << " -- store potential activity: " << (int)cop << "," - // << (int)cop2 << "," - // << " - " << *SI << " of " - // << " Val=" << *Val << "\n"; + if (EnzymePrintActivity) + 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(I)) { bool cop = !Hypothesis->isConstantValue(TR, MTI->getArgOperand(1)); diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll new file mode 100644 index 000000000000..c35ff429e2ab --- /dev/null +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -0,0 +1,103 @@ +; RUN: %opt < %s %newLoadEnzyme -passes="enzyme" -S | llc -filetype=obj -o %t.o +; RUN: %clang %t.o -o %t && %run ./ %t | FileCheck %s + +; ModuleID = 'LLVMDialectModule' +source_filename = "LLVMDialectModule" + +@enzyme_dupnoneed = linkonce constant i8 0 +@enzyme_const = linkonce constant i8 0 + +@.str = private unnamed_addr constant [3 x i8] c"%f\00" + +declare i32 @printf(ptr, ...) + +declare void @__enzyme_autodiff0(...) + +declare void @free(ptr) + +declare ptr @malloc(i64) + +define i32 @main() { + + ; prep arguments & shadows + %input = call ptr @malloc(i64 64) + store double 0.2, ptr %input + %in_shadow = call ptr @malloc(i64 8) + store i64 0, ptr %in_shadow + + %output = call ptr @malloc(i64 8) + %out_shadow = call ptr @malloc(i64 8) + store double 1.000000e+00, ptr %out_shadow + + ; autodiff call + call void (...) @__enzyme_autodiff0(ptr @f.preprocess, ptr %input, ptr %in_shadow, i64 1, ptr %output, ptr %out_shadow) + + ; print result + %grad = load double, ptr %in_shadow + call i32 (ptr, ...) @printf(ptr @.str, double %grad) + + call void @free(ptr %input) + call void @free(ptr %in_shadow) + call void @free(ptr %output) + call void @free(ptr %out_shadow) + + ret i32 0 +} + +; This function just returns 2*input, its derivate should be 2.0. +define void @f.preprocess(ptr %0, i64 %1, ptr %2) { + + ; arithmetic block, changing anything here makes the bug go away + %buffer1 = call ptr @malloc(i64 %1) + %tmp = call ptr @malloc(i64 72) + %4 = ptrtoint ptr %tmp to i64 + %5 = and i64 %4, -64 + %6 = inttoptr i64 %5 to ptr + %7 = load double, ptr %0 + %8 = fmul double %7, 4.000000e+00 + store double %8, ptr %6 + call void @free(ptr %tmp) + store double %8, 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 %0, 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 %0 + %y = fmul double %x, 2.0 + store double %y, ptr %2 + + ret void +} + +; Identity function, 2nd argument required for bug +define void @nested(ptr %0, ptr %1, ptr %2) { + + ; load aligned pointer from %0 & load argument value + %4 = load { ptr, ptr, i64 }, ptr %0 + %5 = extractvalue { ptr, ptr, i64 } %4, 1 + %6 = load double, ptr %5 + + ; load aligned pointer from %2 & store result value + %7 = load { ptr, ptr, i64 }, ptr %2 + %8 = extractvalue { ptr, ptr, i64 } %7, 1 + store double %6, ptr %8 + + ret void +} \ No newline at end of file From 9de9fa79562884df3040147b3cf86bccb6fd2bb8 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Mon, 5 Feb 2024 14:26:47 -0500 Subject: [PATCH 03/17] Add test --- enzyme/test/ActivityAnalysis/integration.ll | 8 +++++--- enzyme/test/lit.site.cfg.py.in | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index c35ff429e2ab..f10afd35a42e 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,5 +1,5 @@ -; RUN: %opt < %s %newLoadEnzyme -passes="enzyme" -S | llc -filetype=obj -o %t.o -; RUN: %clang %t.o -o %t && %run ./ %t | FileCheck %s +; RUN: if [ %llvmver -lt 16 ]; then %opt < %s %loadEnzyme -enzyme -S | %llc -filetype=obj -o output.o && %clang -no-pie output.o -o output && ./output | FileCheck %s +; RUN: %opt < %s %newLoadEnzyme -passes="enzyme" -S | %llc -filetype=obj -o output.o && %clang -no-pie output.o -o output && ./output | FileCheck %s ; ModuleID = 'LLVMDialectModule' source_filename = "LLVMDialectModule" @@ -100,4 +100,6 @@ define void @nested(ptr %0, ptr %1, ptr %2) { store double %6, ptr %8 ret void -} \ No newline at end of file +} + +; CHECK: 2.0 \ No newline at end of file diff --git a/enzyme/test/lit.site.cfg.py.in b/enzyme/test/lit.site.cfg.py.in index 3f4439e09584..8ba90f7da5d2 100644 --- a/enzyme/test/lit.site.cfg.py.in +++ b/enzyme/test/lit.site.cfg.py.in @@ -44,6 +44,7 @@ config.substitutions.append(('%eopt', config.enzyme_obj_root + "/Enzyme/MLIR/enz config.substitutions.append(('%llvmver', config.llvm_ver)) config.substitutions.append(('%FileCheck', config.llvm_tools_dir + "/FileCheck")) config.substitutions.append(('%clang', config.llvm_tools_dir + "/clang")) +config.substitutions.append(('%llc', config.llvm_tools_dir + "/llc")) config.substitutions.append(('%O0TBAA', "-O1 -Xclang -disable-llvm-passes")) oldPM = ((" --enable-new-pm=0" if int(config.llvm_ver) >= 13 else "") From 3f6d7f157805432579e557bd9d73d2126a808d27 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Mon, 5 Feb 2024 16:29:46 -0500 Subject: [PATCH 04/17] Update enzyme/test/ActivityAnalysis/integration.ll --- enzyme/test/ActivityAnalysis/integration.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index f10afd35a42e..8bebfb3f67a3 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -102,4 +102,4 @@ define void @nested(ptr %0, ptr %1, ptr %2) { ret void } -; CHECK: 2.0 \ No newline at end of file +; CHECK: 2.000000 From 0c0e9dde3a7d6b37d461b9c7a0d3607210e86554 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Tue, 6 Feb 2024 16:40:10 -0500 Subject: [PATCH 05/17] Update test --- enzyme/test/ActivityAnalysis/integration.ll | 34 +++++++++++++++++++-- enzyme/test/lit.site.cfg.py.in | 1 - 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index f10afd35a42e..7584ab1ed088 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,5 +1,5 @@ -; RUN: if [ %llvmver -lt 16 ]; then %opt < %s %loadEnzyme -enzyme -S | %llc -filetype=obj -o output.o && %clang -no-pie output.o -o output && ./output | FileCheck %s -; RUN: %opt < %s %newLoadEnzyme -passes="enzyme" -S | %llc -filetype=obj -o output.o && %clang -no-pie output.o -o output && ./output | FileCheck %s +; RUN: if [ %llvmver -lt 16 ]; then %opt < %s %loadEnzyme -print-activity-analysis -activity-analysis-func=f.preprocess -o /dev/null | FileCheck %s; fi +; RUN: %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s ; ModuleID = 'LLVMDialectModule' source_filename = "LLVMDialectModule" @@ -102,4 +102,32 @@ define void @nested(ptr %0, ptr %1, ptr %2) { ret void } -; CHECK: 2.0 \ No newline at end of file +; CHECK: ptr %0: icv:0 +; CHECK-NEXT: i64 %1: icv:1 +; CHECK-NEXT: ptr %2: icv:0 + +; CHECK: %buffer1 = call ptr @malloc(i64 %1): icv:0 ici:1 +; CHECK-NEXT: %tmp = call ptr @malloc(i64 72): icv:1 ici:1 +; CHECK-NEXT: %4 = ptrtoint ptr %tmp to i64: icv:1 ici:1 +; CHECK-NEXT: %5 = and i64 %4, -64: icv:1 ici:1 +; CHECK-NEXT: %6 = inttoptr i64 %5 to ptr: icv:1 ici:1 +; CHECK-NEXT: %7 = load double, ptr %0, align 8: icv:0 ici:0 +; CHECK-NEXT: %8 = fmul double %7, 4.000000e+00: icv:0 ici:0 +; CHECK-NEXT: store double %8, ptr %6, align 8: icv:1 ici:1 +; CHECK-NEXT: call void @free(ptr %tmp): icv:1 ici:1 +; CHECK-NEXT: store double %8, 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 %0, 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 %0, 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 %2, align 8: icv:1 ici:0 +; CHECK-NEXT: ret void: icv:1 ici:1 \ No newline at end of file diff --git a/enzyme/test/lit.site.cfg.py.in b/enzyme/test/lit.site.cfg.py.in index 6a19a0f1cef7..481fce924bcc 100644 --- a/enzyme/test/lit.site.cfg.py.in +++ b/enzyme/test/lit.site.cfg.py.in @@ -64,7 +64,6 @@ if len("@ENZYME_BINARY_DIR@") == 0: config.substitutions.append(('%eopt', emopt)) config.substitutions.append(('%llvmver', config.llvm_ver)) config.substitutions.append(('%FileCheck', config.llvm_tools_dir + "/FileCheck")) -config.substitutions.append(('%llc', config.llvm_tools_dir + "/llc")) config.substitutions.append(('%clang', eclang)) config.substitutions.append(('%O0TBAA', "-O1 -Xclang -disable-llvm-passes")) From e13767a199eab1de08f36a8e3f2d20fb837b8f93 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Tue, 13 Feb 2024 22:43:19 -0500 Subject: [PATCH 06/17] Update test --- enzyme/test/ActivityAnalysis/integration.ll | 144 +++++++------------- 1 file changed, 52 insertions(+), 92 deletions(-) diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index 89566abff022..bc87de26a388 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,68 +1,28 @@ -; RUN: if [ %llvmver -lt 16 ]; then %opt < %s %loadEnzyme -print-activity-analysis -activity-analysis-func=f.preprocess -o /dev/null | FileCheck %s; fi -; RUN: %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s - -; ModuleID = 'LLVMDialectModule' -source_filename = "LLVMDialectModule" - -@enzyme_dupnoneed = linkonce constant i8 0 -@enzyme_const = linkonce constant i8 0 - -@.str = private unnamed_addr constant [3 x i8] c"%f\00" - -declare i32 @printf(ptr, ...) - -declare void @__enzyme_autodiff0(...) +; RUN: if [ %llvmver -gt 16 ]; %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s declare void @free(ptr) declare ptr @malloc(i64) -define i32 @main() { - - ; prep arguments & shadows - %input = call ptr @malloc(i64 64) - store double 0.2, ptr %input - %in_shadow = call ptr @malloc(i64 8) - store i64 0, ptr %in_shadow - - %output = call ptr @malloc(i64 8) - %out_shadow = call ptr @malloc(i64 8) - store double 1.000000e+00, ptr %out_shadow - - ; autodiff call - call void (...) @__enzyme_autodiff0(ptr @f.preprocess, ptr %input, ptr %in_shadow, i64 1, ptr %output, ptr %out_shadow) - - ; print result - %grad = load double, ptr %in_shadow - call i32 (ptr, ...) @printf(ptr @.str, double %grad) - - call void @free(ptr %input) - call void @free(ptr %in_shadow) - call void @free(ptr %output) - call void @free(ptr %out_shadow) - - ret i32 0 -} - ; This function just returns 2*input, its derivate should be 2.0. -define void @f.preprocess(ptr %0, i64 %1, ptr %2) { +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 %1) + %buffer1 = call ptr @malloc(i64 %mallocsize) %tmp = call ptr @malloc(i64 72) - %4 = ptrtoint ptr %tmp to i64 - %5 = and i64 %4, -64 - %6 = inttoptr i64 %5 to ptr - %7 = load double, ptr %0 - %8 = fmul double %7, 4.000000e+00 - store double %8, ptr %6 + %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 %8, ptr %buffer1 + 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 %0, ptr %arg0_aligned + 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] } @@ -79,55 +39,55 @@ define void @f.preprocess(ptr %0, i64 %1, ptr %2) { 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 %0 + %x = load double, ptr %param %y = fmul double %x, 2.0 - store double %y, ptr %2 + store double %y, ptr %res ret void } -; Identity function, 2nd argument required for bug -define void @nested(ptr %0, ptr %1, ptr %2) { +; Identity function, 2nd argument required for bug (but not used) +define void @nested(ptr %arg0, ptr %arg1, ptr %arg2) { - ; load aligned pointer from %0 & load argument value - %4 = load { ptr, ptr, i64 }, ptr %0 - %5 = extractvalue { ptr, ptr, i64 } %4, 1 - %6 = load double, ptr %5 + ; 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 %2 & store result value - %7 = load { ptr, ptr, i64 }, ptr %2 - %8 = extractvalue { ptr, ptr, i64 } %7, 1 - store double %6, ptr %8 + ; 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 %0: icv:0 -; CHECK-NEXT: i64 %1: icv:1 -; CHECK-NEXT: ptr %2: icv:0 - -; CHECK: %buffer1 = call ptr @malloc(i64 %1): icv:0 ici:1 -; CHECK-NEXT: %tmp = call ptr @malloc(i64 72): icv:1 ici:1 -; CHECK-NEXT: %4 = ptrtoint ptr %tmp to i64: icv:1 ici:1 -; CHECK-NEXT: %5 = and i64 %4, -64: icv:1 ici:1 -; CHECK-NEXT: %6 = inttoptr i64 %5 to ptr: icv:1 ici:1 -; CHECK-NEXT: %7 = load double, ptr %0, align 8: icv:0 ici:0 -; CHECK-NEXT: %8 = fmul double %7, 4.000000e+00: icv:0 ici:0 -; CHECK-NEXT: store double %8, ptr %6, align 8: icv:1 ici:1 -; CHECK-NEXT: call void @free(ptr %tmp): icv:1 ici:1 -; CHECK-NEXT: store double %8, 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 %0, 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 %0, 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 %2, align 8: icv:1 ici:0 -; CHECK-NEXT: ret void: icv:1 ici:1 +; 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 \ No newline at end of file From 4e2a53c4c76d21247a88a358fc48a24dd021c77e Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Tue, 13 Feb 2024 22:45:19 -0500 Subject: [PATCH 07/17] Add missing return --- enzyme/test/ActivityAnalysis/integration.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index bc87de26a388..007d6187a7a2 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -90,4 +90,4 @@ define void @nested(ptr %arg0, ptr %arg1, ptr %arg2) { ; 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 \ No newline at end of file +; CHECK-NEXT: ret void: icv:1 ici:1 From b7dfd22c45eb8e13aabfa2c09758a4d188a546ee Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Thu, 15 Feb 2024 15:24:32 -0500 Subject: [PATCH 08/17] Format and test --- enzyme/Enzyme/ActivityAnalysis.cpp | 3 ++- enzyme/test/ActivityAnalysis/integration.ll | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/enzyme/Enzyme/ActivityAnalysis.cpp b/enzyme/Enzyme/ActivityAnalysis.cpp index 5b34e6d87d10..96af8dcf2d22 100644 --- a/enzyme/Enzyme/ActivityAnalysis.cpp +++ b/enzyme/Enzyme/ActivityAnalysis.cpp @@ -2071,7 +2071,8 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) { << "\n"; if (auto SI = dyn_cast(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 << " - " << *SI << " of " diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index 007d6187a7a2..93e4c43f7b13 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,4 +1,4 @@ -; RUN: if [ %llvmver -gt 16 ]; %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s +; RUN: if [ %llvmver -ge 16 ]; then %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s declare void @free(ptr) From d5c3f18440d79497b9d1957e38c92d38a8993f57 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Thu, 15 Feb 2024 15:25:03 -0500 Subject: [PATCH 09/17] Back gt --- enzyme/test/ActivityAnalysis/integration.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index 93e4c43f7b13..3b5473c30b92 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,4 +1,4 @@ -; RUN: if [ %llvmver -ge 16 ]; then %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s +; RUN: if [ %llvmver -gt 16 ]; then %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s declare void @free(ptr) From cb449a3b011df7019f3c6a4946bb654c31a09f04 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Fri, 16 Feb 2024 13:27:20 -0500 Subject: [PATCH 10/17] Test fix trial --- enzyme/test/ActivityAnalysis/integration.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index 3b5473c30b92..c51d5009bdab 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,4 +1,4 @@ -; RUN: if [ %llvmver -gt 16 ]; then %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s +; RUN: if [ %llvmver -gt 16 ]; then %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s; fi declare void @free(ptr) From ddbad85a7cbaed1c3cb4a35cbddb6bdc9c9aefe7 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Fri, 16 Feb 2024 14:37:30 -0500 Subject: [PATCH 11/17] Lower test llvm to 15 --- enzyme/test/ActivityAnalysis/integration.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index c51d5009bdab..1dd8f45c1e07 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,4 +1,4 @@ -; RUN: if [ %llvmver -gt 16 ]; then %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s; fi +; RUN: if [ %llvmver -gt 15 ]; then %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s; fi declare void @free(ptr) From dd02508951537f8bbe13ce866cefc40c51a35a52 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Fri, 16 Feb 2024 18:23:45 -0500 Subject: [PATCH 12/17] Update enzyme/test/ActivityAnalysis/integration.ll --- enzyme/test/ActivityAnalysis/integration.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index 1dd8f45c1e07..4c21ecc7a128 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,4 +1,4 @@ -; RUN: if [ %llvmver -gt 15 ]; then %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s; fi +; RUN: if [ %llvmver -gt 15 ]; then %opt < %s %OPnewLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s; fi declare void @free(ptr) From d560062b2c501aa89370b80be3b83b2d1734ac27 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Fri, 16 Feb 2024 20:46:42 -0500 Subject: [PATCH 13/17] Update activity printer for opaque type --- enzyme/Enzyme/ActivityAnalysisPrinter.cpp | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp index a69d7c9e56e8..8b72a2497309 100644 --- a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp +++ b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp @@ -91,11 +91,13 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { } else if (a.getType()->isPointerTy()) { #if LLVM_VERSION_MAJOR >= 17 #else - auto et = a.getType()->getPointerElementType(); - if (et->isFPOrFPVectorTy()) { - dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); - } else if (et->isPointerTy()) { - dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); + if (!a.getType().isOpaquePointerTy()) { + auto et = a.getType()->getPointerElementType(); + if (et->isFPOrFPVectorTy()) { + dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); + } else if (et->isPointerTy()) { + dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); + } } #endif } else if (a.getType()->isIntOrIntVectorTy()) { @@ -115,11 +117,13 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { } else if (F.getReturnType()->isPointerTy()) { #if LLVM_VERSION_MAJOR >= 17 #else - auto et = F.getReturnType()->getPointerElementType(); - if (et->isFPOrFPVectorTy()) { - dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); - } else if (et->isPointerTy()) { - dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); + if (!F.getReturnType().isOpaquePointerTy()) { + auto et = F.getReturnType()->getPointerElementType(); + if (et->isFPOrFPVectorTy()) { + dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); + } else if (et->isPointerTy()) { + dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); + } } #endif } else if (F.getReturnType()->isIntOrIntVectorTy()) { From 87efd97bdd14fdc49d16c576803f9d9ed0d43318 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Fri, 16 Feb 2024 20:51:02 -0500 Subject: [PATCH 14/17] update -> --- enzyme/Enzyme/ActivityAnalysisPrinter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp index 8b72a2497309..a2834e18532e 100644 --- a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp +++ b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp @@ -91,7 +91,7 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { } else if (a.getType()->isPointerTy()) { #if LLVM_VERSION_MAJOR >= 17 #else - if (!a.getType().isOpaquePointerTy()) { + if (!a.getType()->isOpaquePointerTy()) { auto et = a.getType()->getPointerElementType(); if (et->isFPOrFPVectorTy()) { dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); @@ -117,7 +117,7 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { } else if (F.getReturnType()->isPointerTy()) { #if LLVM_VERSION_MAJOR >= 17 #else - if (!F.getReturnType().isOpaquePointerTy()) { + if (!F.getReturnType()->isOpaquePointerTy()) { auto et = F.getReturnType()->getPointerElementType(); if (et->isFPOrFPVectorTy()) { dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); From 8919afd85914e303b9609348ca8890b52be24361 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Fri, 16 Feb 2024 21:58:09 -0500 Subject: [PATCH 15/17] Update activity analysis --- enzyme/Enzyme/ActivityAnalysisPrinter.cpp | 18 ++++++++++++------ enzyme/test/ActivityAnalysis/integration.ll | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp index a2834e18532e..700e9ef7e583 100644 --- a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp +++ b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp @@ -89,9 +89,13 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { if (a.getType()->isFPOrFPVectorTy()) { dt = ConcreteType(a.getType()->getScalarType()); } else if (a.getType()->isPointerTy()) { + bool opaque = false; #if LLVM_VERSION_MAJOR >= 17 -#else - if (!a.getType()->isOpaquePointerTy()) { + opaque = true; +#elif LLVM_VERSION_MAJOR >= 13 + opaque = a.getType()->isOpaquePointerTy(); +#endif + if (!opaque) { auto et = a.getType()->getPointerElementType(); if (et->isFPOrFPVectorTy()) { dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); @@ -99,7 +103,6 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); } } -#endif } else if (a.getType()->isIntOrIntVectorTy()) { dt = ConcreteType(BaseType::Integer); } @@ -115,9 +118,13 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { if (F.getReturnType()->isFPOrFPVectorTy()) { dt = ConcreteType(F.getReturnType()->getScalarType()); } else if (F.getReturnType()->isPointerTy()) { + bool opaque = false; #if LLVM_VERSION_MAJOR >= 17 -#else - if (!F.getReturnType()->isOpaquePointerTy()) { + opaque = true; +#elif LLVM_VERSION_MAJOR >= 13 + opaque = F.getType()->isOpaquePointerTy(); +#endif + if (!opaque) { auto et = F.getReturnType()->getPointerElementType(); if (et->isFPOrFPVectorTy()) { dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); @@ -125,7 +132,6 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); } } -#endif } else if (F.getReturnType()->isIntOrIntVectorTy()) { dt = ConcreteType(BaseType::Integer); } diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index 4c21ecc7a128..df9c73b0cbe3 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,4 +1,4 @@ -; RUN: if [ %llvmver -gt 15 ]; then %opt < %s %OPnewLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess-S | FileCheck %s; fi +; RUN: if [ %llvmver -gt 15 ]; then %opt < %s %OPnewLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess -S | FileCheck %s; fi declare void @free(ptr) From c88b9f48bd68c6391fd8772d549561d42e4c25be Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Fri, 16 Feb 2024 22:09:21 -0500 Subject: [PATCH 16/17] Update if/elif llvm --- enzyme/Enzyme/ActivityAnalysisPrinter.cpp | 28 +++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp index 700e9ef7e583..1d4db75c31a1 100644 --- a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp +++ b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp @@ -89,13 +89,9 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { if (a.getType()->isFPOrFPVectorTy()) { dt = ConcreteType(a.getType()->getScalarType()); } else if (a.getType()->isPointerTy()) { - bool opaque = false; #if LLVM_VERSION_MAJOR >= 17 - opaque = true; #elif LLVM_VERSION_MAJOR >= 13 - opaque = a.getType()->isOpaquePointerTy(); -#endif - if (!opaque) { + if (!a.getType()->isOpaquePointerTy()) { auto et = a.getType()->getPointerElementType(); if (et->isFPOrFPVectorTy()) { dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); @@ -103,6 +99,14 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); } } +#else + auto et = a.getType()->getPointerElementType(); + if (et->isFPOrFPVectorTy()) { + dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); + } else if (et->isPointerTy()) { + dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); + } +#endif } else if (a.getType()->isIntOrIntVectorTy()) { dt = ConcreteType(BaseType::Integer); } @@ -118,13 +122,9 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { if (F.getReturnType()->isFPOrFPVectorTy()) { dt = ConcreteType(F.getReturnType()->getScalarType()); } else if (F.getReturnType()->isPointerTy()) { - bool opaque = false; #if LLVM_VERSION_MAJOR >= 17 - opaque = true; #elif LLVM_VERSION_MAJOR >= 13 - opaque = F.getType()->isOpaquePointerTy(); -#endif - if (!opaque) { + if (!F.getType()->isOpaquePointerTy()) { auto et = F.getReturnType()->getPointerElementType(); if (et->isFPOrFPVectorTy()) { dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); @@ -132,6 +132,14 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); } } +#else + auto et = F.getReturnType()->getPointerElementType(); + if (et->isFPOrFPVectorTy()) { + dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); + } else if (et->isPointerTy()) { + dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); + } +#endif } else if (F.getReturnType()->isIntOrIntVectorTy()) { dt = ConcreteType(BaseType::Integer); } From cada4fecdf211f6efc08430079032a014bf0faf7 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Tue, 20 Feb 2024 11:12:47 -0500 Subject: [PATCH 17/17] Update llvm versioning --- enzyme/Enzyme/ActivityAnalysisPrinter.cpp | 32 ++++++++------------- enzyme/test/ActivityAnalysis/integration.ll | 2 +- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp index 1d4db75c31a1..bfca7860fc45 100644 --- a/enzyme/Enzyme/ActivityAnalysisPrinter.cpp +++ b/enzyme/Enzyme/ActivityAnalysisPrinter.cpp @@ -89,23 +89,19 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { if (a.getType()->isFPOrFPVectorTy()) { dt = ConcreteType(a.getType()->getScalarType()); } else if (a.getType()->isPointerTy()) { -#if LLVM_VERSION_MAJOR >= 17 -#elif LLVM_VERSION_MAJOR >= 13 - if (!a.getType()->isOpaquePointerTy()) { +#if LLVM_VERSION_MAJOR < 17 +#if LLVM_VERSION_MAJOR >= 13 + if (a.getContext().supportsTypedPointers()) { +#endif auto et = a.getType()->getPointerElementType(); if (et->isFPOrFPVectorTy()) { dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); } else if (et->isPointerTy()) { dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); } +#if LLVM_VERSION_MAJOR >= 13 } -#else - auto et = a.getType()->getPointerElementType(); - if (et->isFPOrFPVectorTy()) { - dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); - } else if (et->isPointerTy()) { - dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); - } +#endif #endif } else if (a.getType()->isIntOrIntVectorTy()) { dt = ConcreteType(BaseType::Integer); @@ -122,23 +118,19 @@ bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) { if (F.getReturnType()->isFPOrFPVectorTy()) { dt = ConcreteType(F.getReturnType()->getScalarType()); } else if (F.getReturnType()->isPointerTy()) { -#if LLVM_VERSION_MAJOR >= 17 -#elif LLVM_VERSION_MAJOR >= 13 - if (!F.getType()->isOpaquePointerTy()) { +#if LLVM_VERSION_MAJOR < 17 +#if LLVM_VERSION_MAJOR >= 13 + if (F.getContext().supportsTypedPointers()) { +#endif auto et = F.getReturnType()->getPointerElementType(); if (et->isFPOrFPVectorTy()) { dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); } else if (et->isPointerTy()) { dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); } +#if LLVM_VERSION_MAJOR >= 13 } -#else - auto et = F.getReturnType()->getPointerElementType(); - if (et->isFPOrFPVectorTy()) { - dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr); - } else if (et->isPointerTy()) { - dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr); - } +#endif #endif } else if (F.getReturnType()->isIntOrIntVectorTy()) { dt = ConcreteType(BaseType::Integer); diff --git a/enzyme/test/ActivityAnalysis/integration.ll b/enzyme/test/ActivityAnalysis/integration.ll index df9c73b0cbe3..28ce009a9b5b 100644 --- a/enzyme/test/ActivityAnalysis/integration.ll +++ b/enzyme/test/ActivityAnalysis/integration.ll @@ -1,4 +1,4 @@ -; RUN: if [ %llvmver -gt 15 ]; then %opt < %s %OPnewLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess -S | FileCheck %s; fi +; RUN: if [ %llvmver -ge 15 ]; then %opt < %s %OPnewLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=f.preprocess -S | FileCheck %s; fi declare void @free(ptr)