Skip to content

Commit ca1bc8e

Browse files
committed
union and usize added
Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
1 parent 2e3b056 commit ca1bc8e

File tree

6 files changed

+104
-0
lines changed

6 files changed

+104
-0
lines changed

tests/ui/autodiff/union.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ run-pass
2+
//@ compile-flags: -Zautodiff=Enable,PrintTAFn=callee -Zautodiff=NoPostopt -C opt-level=3 -Clto=fat -g
3+
//@ no-prefer-dynamic
4+
//@ needs-enzyme
5+
//@ normalize-stderr: "!(dbg|noundef) ![0-9]+" -> "!$1 !N"
6+
//@ normalize-stderr: "%[0-9]+" -> "%X"
7+
//@ normalize-stdout: "!(dbg|noundef) ![0-9]+" -> "!$1 !N"
8+
//@ normalize-stdout: "%[0-9]+" -> "%X"
9+
10+
#![feature(autodiff)]
11+
12+
use std::autodiff::autodiff_reverse;
13+
14+
#[allow(dead_code)]
15+
union MyUnion {
16+
f: f32,
17+
i: i32,
18+
}
19+
20+
#[autodiff_reverse(d_square, Duplicated, Active)]
21+
#[no_mangle]
22+
fn callee(x: &MyUnion) -> f32 {
23+
unsafe { x.f * x.f }
24+
}
25+
26+
fn main() {
27+
let x = MyUnion { f: 7.0 };
28+
let _ = callee(&x);
29+
}

tests/ui/autodiff/union.stderr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
analyzing function callee
2+
+ knowndata: ptr %X : {[-1]:Pointer} - {}
3+
+ retdata: {[-1]:Float@float}
4+
updating analysis of val: ptr %X current: {} new {[-1]:Pointer} from ptr %X Changed=1 legal=1
5+
updating analysis of val: ptr %X current: {[-1]:Pointer} new {[-1]:Pointer} from ptr %X Changed=0 legal=1
6+
updating analysis of val: %X = fmul float %X, %X, !dbg !N current: {} new {[-1]:Float@float} from %X = fmul float %X, %X, !dbg !N Changed=1 legal=1
7+
updating analysis of val: %X = fmul float %X, %X, !dbg !N current: {[-1]:Float@float} new {[-1]:Float@float} from %X = fmul float %X, %X, !dbg !N Changed=0 legal=1
8+
updating analysis of val: ptr %X current: {[-1]:Pointer} new {[-1]:Pointer} from %X = load float, ptr %X, align 4, !dbg !N, !noundef !N Changed=0 legal=1
9+
updating analysis of val: %X = load float, ptr %X, align 4, !dbg !N, !noundef !N current: {} new {} from %X = load float, ptr %X, align 4, !dbg !N, !noundef !N Changed=0 legal=1
10+
updating analysis of val: %X = load float, ptr %X, align 4, !dbg !N, !noundef !N current: {} new {[-1]:Float@float} from %X = fmul float %X, %X, !dbg !N Changed=1 legal=1
11+
updating analysis of val: %X = load float, ptr %X, align 4, !dbg !N, !noundef !N current: {[-1]:Float@float} new {[-1]:Float@float} from %X = fmul float %X, %X, !dbg !N Changed=0 legal=1
12+
updating analysis of val: %X = fmul float %X, %X, !dbg !N current: {[-1]:Float@float} new {[-1]:Float@float} from %X = fmul float %X, %X, !dbg !N Changed=0 legal=1
13+
updating analysis of val: ptr %X current: {[-1]:Pointer} new {[-1]:Pointer, [-1,0]:Float@float} from %X = load float, ptr %X, align 4, !dbg !N, !noundef !N Changed=1 legal=1
14+
updating analysis of val: %X = load float, ptr %X, align 4, !dbg !N, !noundef !N current: {[-1]:Float@float} new {[-1]:Float@float} from %X = load float, ptr %X, align 4, !dbg !N, !noundef !N Changed=0 legal=1

tests/ui/autodiff/union.stdout

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
callee - {[-1]:Float@float} |{[-1]:Pointer}:{}
2+
ptr %X: {[-1]:Pointer, [-1,0]:Float@float}
3+
4+
%X = load float, ptr %X, align 4, !dbg !N, !noundef !N: {[-1]:Float@float}
5+
%X = fmul float %X, %X, !dbg !N: {[-1]:Float@float}
6+
ret float %X, !dbg !N: {}
7+
callee - {[-1]:Float@float} |{[-1]:Pointer, [-1,0]:Float@float}:{}
8+
ptr %X: {[-1]:Pointer, [-1,0]:Float@float}
9+
10+
%X = load float, ptr %X, align 4, !dbg !N, !noundef !N: {[-1]:Float@float}
11+
%X = fmul float %X, %X, !dbg !N: {[-1]:Float@float}
12+
ret float %X, !dbg !N: {}

tests/ui/autodiff/usize.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ run-pass
2+
//@ compile-flags: -Zautodiff=Enable,PrintTAFn=callee -Zautodiff=NoPostopt -C opt-level=3 -Clto=fat -g
3+
//@ no-prefer-dynamic
4+
//@ needs-enzyme
5+
//@ normalize-stderr: "!(dbg|noundef) ![0-9]+" -> "!$1 !N"
6+
//@ normalize-stderr: "%[0-9]+" -> "%X"
7+
//@ normalize-stdout: "!(dbg|noundef) ![0-9]+" -> "!$1 !N"
8+
//@ normalize-stdout: "%[0-9]+" -> "%X"
9+
10+
#![feature(autodiff)]
11+
12+
use std::autodiff::autodiff_reverse;
13+
14+
#[autodiff_reverse(d_square, Duplicated, Active)]
15+
#[no_mangle]
16+
fn callee(x: &usize) -> usize {
17+
*x * *x
18+
}
19+
20+
fn main() {
21+
let x: usize = 7;
22+
let _ = callee(&x);
23+
}

tests/ui/autodiff/usize.stderr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
analyzing function callee
2+
+ knowndata: ptr %X : {[-1]:Pointer} - {}
3+
+ retdata: {[-1]:Integer}
4+
updating analysis of val: ptr %X current: {} new {[-1]:Pointer} from ptr %X Changed=1 legal=1
5+
updating analysis of val: ptr %X current: {[-1]:Pointer} new {[-1]:Pointer} from ptr %X Changed=0 legal=1
6+
updating analysis of val: %X = mul i64 %X, %X, !dbg !N current: {} new {[-1]:Integer} from %X = mul i64 %X, %X, !dbg !N Changed=1 legal=1
7+
updating analysis of val: %X = mul i64 %X, %X, !dbg !N current: {[-1]:Integer} new {[-1]:Integer} from %X = mul i64 %X, %X, !dbg !N Changed=0 legal=1
8+
updating analysis of val: ptr %X current: {[-1]:Pointer} new {[-1]:Pointer} from %X = load i64, ptr %X, align 8, !dbg !N, !noundef !N Changed=0 legal=1
9+
updating analysis of val: %X = load i64, ptr %X, align 8, !dbg !N, !noundef !N current: {} new {} from %X = load i64, ptr %X, align 8, !dbg !N, !noundef !N Changed=0 legal=1
10+
updating analysis of val: %X = load i64, ptr %X, align 8, !dbg !N, !noundef !N current: {} new {[-1]:Integer} from %X = mul i64 %X, %X, !dbg !N Changed=1 legal=1
11+
updating analysis of val: %X = load i64, ptr %X, align 8, !dbg !N, !noundef !N current: {[-1]:Integer} new {[-1]:Integer} from %X = mul i64 %X, %X, !dbg !N Changed=0 legal=1
12+
updating analysis of val: %X = mul i64 %X, %X, !dbg !N current: {[-1]:Integer} new {} from %X = mul i64 %X, %X, !dbg !N Changed=0 legal=1
13+
updating analysis of val: ptr %X current: {[-1]:Pointer} new {[-1]:Pointer, [-1,0]:Integer, [-1,1]:Integer, [-1,2]:Integer, [-1,3]:Integer, [-1,4]:Integer, [-1,5]:Integer, [-1,6]:Integer, [-1,7]:Integer} from %X = load i64, ptr %X, align 8, !dbg !N, !noundef !N Changed=1 legal=1
14+
updating analysis of val: %X = load i64, ptr %X, align 8, !dbg !N, !noundef !N current: {[-1]:Integer} new {[-1]:Integer} from %X = load i64, ptr %X, align 8, !dbg !N, !noundef !N Changed=0 legal=1

tests/ui/autodiff/usize.stdout

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
callee - {[-1]:Integer} |{[-1]:Pointer}:{}
2+
ptr %X: {[-1]:Pointer, [-1,0]:Integer, [-1,1]:Integer, [-1,2]:Integer, [-1,3]:Integer, [-1,4]:Integer, [-1,5]:Integer, [-1,6]:Integer, [-1,7]:Integer}
3+
4+
%X = load i64, ptr %X, align 8, !dbg !N, !noundef !N: {[-1]:Integer}
5+
%X = mul i64 %X, %X, !dbg !N: {[-1]:Integer}
6+
ret i64 %X, !dbg !N: {}
7+
callee - {[-1]:Integer} |{[-1]:Pointer, [-1,0]:Integer, [-1,1]:Integer, [-1,2]:Integer, [-1,3]:Integer, [-1,4]:Integer, [-1,5]:Integer, [-1,6]:Integer, [-1,7]:Integer}:{}
8+
ptr %X: {[-1]:Pointer, [-1,0]:Integer, [-1,1]:Integer, [-1,2]:Integer, [-1,3]:Integer, [-1,4]:Integer, [-1,5]:Integer, [-1,6]:Integer, [-1,7]:Integer}
9+
10+
%X = load i64, ptr %X, align 8, !dbg !N, !noundef !N: {[-1]:Integer}
11+
%X = mul i64 %X, %X, !dbg !N: {[-1]:Integer}
12+
ret i64 %X, !dbg !N: {}

0 commit comments

Comments
 (0)