From 2223fc1724182decaeb697636c1a2bda95ee6794 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Sun, 27 Dec 2020 17:39:09 -0500 Subject: [PATCH] Fix usage of anything type in activity analysis --- enzyme/Enzyme/TypeAnalysis/ConcreteType.h | 9 ++--- enzyme/test/Enzyme/constselect.ll | 49 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 enzyme/test/Enzyme/constselect.ll diff --git a/enzyme/Enzyme/TypeAnalysis/ConcreteType.h b/enzyme/Enzyme/TypeAnalysis/ConcreteType.h index a4b4b62d2116..803b3cfd83a4 100644 --- a/enzyme/Enzyme/TypeAnalysis/ConcreteType.h +++ b/enzyme/Enzyme/TypeAnalysis/ConcreteType.h @@ -118,11 +118,9 @@ class ConcreteType { /// Whether this ConcreteType has information (is not unknown) bool isKnown() const { return SubTypeEnum != BaseType::Unknown; } - /// Whether this ConcreteType can be used as an integer (SubTypeEnum is - /// Integer or Anything) + /// Whether this ConcreteType must an integer bool isIntegral() const { - return SubTypeEnum == BaseType::Integer || - SubTypeEnum == BaseType::Anything; + return SubTypeEnum == BaseType::Integer; } /// Whether this ConcreteType could be a pointer (SubTypeEnum is unknown or a @@ -134,7 +132,8 @@ class ConcreteType { /// Whether this ConcreteType could be a float (SubTypeEnum is unknown or a /// float) bool isPossibleFloat() const { - return !isKnown() || SubTypeEnum == BaseType::Float; + return !isKnown() || SubTypeEnum == BaseType::Float + || SubTypeEnum == BaseType::Anything; } /// Return the floating point type, if this is a float diff --git a/enzyme/test/Enzyme/constselect.ll b/enzyme/test/Enzyme/constselect.ll new file mode 100644 index 000000000000..59f415067a8d --- /dev/null +++ b/enzyme/test/Enzyme/constselect.ll @@ -0,0 +1,49 @@ +; RUN: %opt < %s %loadEnzyme -enzyme -enzyme-preopt=false -mem2reg -sroa -instsimplify -simplifycfg -S | FileCheck %s + +; ModuleID = 'inp.c' +source_filename = "inp.c" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str = private unnamed_addr constant [20 x i8] c"dfun/dx = %f, x=%d\0A\00", align 1 + +; Function Attrs: norecurse nounwind readnone uwtable +define double @fun2(double %x) { +entry: + %cmp.inv = fcmp oge double %x, 0.000000e+00 + %.x = select i1 %cmp.inv, double %x, double 0.000000e+00 + ret double %.x +} + +; Function Attrs: nounwind uwtable +define i32 @main() { +entry: + %call3.4 = tail call double (i8*, ...) @__enzyme_autodiff(i8* bitcast (double (double)* @fun2 to i8*), double 2.000000e+00) + %call4.4 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %call3.4, i32 2) + ret i32 0 +} + +; Function Attrs: nounwind +declare dso_local i32 @printf(i8* nocapture readonly, ...) + +declare double @__enzyme_autodiff(i8*, ...) + +attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #3 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #4 = { nounwind } + +!llvm.module.flags = !{!0} +!llvm.ident = !{!1} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{!"clang version 7.1.0 "} + +; CHECK: define internal { double } @diffefun2(double %x, double %differeturn) +; CHECK-NEXT: entry: +; CHECK-NEXT: %cmp.inv = fcmp oge double %x, 0.000000e+00 +; CHECK-NEXT: %0 = select{{( fast)?}} i1 %cmp.inv, double %differeturn, double 0.000000e+00 +; CHECK-NEXT: %1 = insertvalue { double } undef, double %0, 0 +; CHECK-NEXT: ret { double } %1 +; CHECK-NEXT: } \ No newline at end of file