Skip to content

Commit

Permalink
Fix usage of anything type in activity analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Dec 27, 2020
1 parent a86314f commit 2223fc1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
9 changes: 4 additions & 5 deletions enzyme/Enzyme/TypeAnalysis/ConcreteType.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
49 changes: 49 additions & 0 deletions enzyme/test/Enzyme/constselect.ll
Original file line number Diff line number Diff line change
@@ -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: }

0 comments on commit 2223fc1

Please sign in to comment.