Rust · 2705 bytes Raw Blame History
1 use std::collections::BTreeSet;
2 use std::path::PathBuf;
3
4 use armfortas::driver::OptLevel;
5 use armfortas::testing::{capture_from_path, CaptureRequest, CapturedStage, Stage};
6
7 fn fixture(name: &str) -> PathBuf {
8 let path = PathBuf::from("test_programs").join(name);
9 assert!(path.exists(), "missing test fixture {}", path.display());
10 path
11 }
12
13 fn capture_text(request: CaptureRequest, stage: Stage) -> String {
14 let result = capture_from_path(&request).expect("capture should succeed");
15 match result.get(stage) {
16 Some(CapturedStage::Text(text)) => text.clone(),
17 Some(CapturedStage::Run(_)) => panic!("expected text stage for {}", stage.as_str()),
18 None => panic!("missing requested stage {}", stage.as_str()),
19 }
20 }
21
22 fn capture_run_stdout(request: CaptureRequest) -> String {
23 let result = capture_from_path(&request).expect("capture should succeed");
24 match result.get(Stage::Run) {
25 Some(CapturedStage::Run(run)) => run.stdout.clone(),
26 _ => panic!("missing run stage"),
27 }
28 }
29
30 #[test]
31 fn o3_vectorizes_elementwise_minmax_binary() {
32 let source = fixture("do_loop_vectorize_minmax_binary.f90");
33
34 let o3_ir = capture_text(
35 CaptureRequest {
36 input: source.clone(),
37 requested: BTreeSet::from([Stage::OptIr]),
38 opt_level: OptLevel::O3,
39 },
40 Stage::OptIr,
41 );
42 // Three vmax (i32, f32, f64) and three vmin (i32, f32, f64).
43 assert_eq!(
44 o3_ir.matches("vmax").count(),
45 3,
46 "expected three vmax:\n{}",
47 o3_ir
48 );
49 assert_eq!(
50 o3_ir.matches("vmin").count(),
51 3,
52 "expected three vmin:\n{}",
53 o3_ir
54 );
55
56 let stdout = capture_run_stdout(CaptureRequest {
57 input: source,
58 requested: BTreeSet::from([Stage::Run]),
59 opt_level: OptLevel::O3,
60 });
61 let trimmed: Vec<&str> = stdout
62 .lines()
63 .map(|l| l.trim())
64 .filter(|l| !l.is_empty())
65 .collect();
66 assert_eq!(trimmed.len(), 6, "expected six output lines:\n{}", stdout);
67 // i32 max @ {1,16,17,32} => {32,17,17,32}; i32 min => {1,16,16,1}.
68 assert_eq!(trimmed[0], "32 17 17 32", "i32 max wrong: {:?}", trimmed[0]);
69 assert_eq!(trimmed[1], "1 16 16 1", "i32 min wrong: {:?}", trimmed[1]);
70 // f32 / f64 max start "3.2"; min start "1.".
71 for max_line in [trimmed[2], trimmed[4]] {
72 assert!(
73 max_line.starts_with("3.2"),
74 "fp max wrong: {:?}",
75 max_line
76 );
77 }
78 for min_line in [trimmed[3], trimmed[5]] {
79 assert!(
80 min_line.starts_with("1."),
81 "fp min wrong: {:?}",
82 min_line
83 );
84 }
85 }
86