Skip to content

Commit 0fe066b

Browse files
dguzhaevigcbot
authored andcommitted
Updated CustomSafeOpt lit tests
Tests update
1 parent 820aee8 commit 0fe066b

22 files changed

+1341
-533
lines changed

IGC/Compiler/tests/CustomSafeOptPass/DebugInfo_CustomSafeOptPass_xor-typed-pointers.ll

Lines changed: 0 additions & 103 deletions
This file was deleted.

IGC/Compiler/tests/CustomSafeOptPass/DebugInfo_CustomSafeOptPass_xor.ll

Lines changed: 0 additions & 104 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; RUN: igc_opt -igc-custom-safe-opt -S < %s | FileCheck %s
10+
11+
; CustomSafeOpt will try to move addition with constant, from
12+
; %1 = add i32 %a, 14
13+
; %2 = add i32 %1, %b
14+
; to
15+
; %1 = add i32 %a, %b
16+
; %2 = add i32 %1, 14
17+
18+
define i32 @test_customsafe_add(i32 %a, i32 %b) {
19+
; CHECK-LABEL: @test_customsafe_add(
20+
; CHECK: [[TMP1:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
21+
; CHECK: [[TMP2:%.*]] = add i32 [[TMP1]], 14
22+
; CHECK: ret i32 [[TMP2]]
23+
;
24+
%1 = add i32 %a, 14
25+
%2 = add i32 %1, %b
26+
ret i32 %2
27+
}
28+
29+
; nuw is propagated only if set on both adds
30+
31+
define i32 @test_customsafe_add_nuw(i32 %a, i32 %b) {
32+
; CHECK-LABEL: @test_customsafe_add_nuw(
33+
; CHECK: [[TMP1:%.*]] = add nuw i32 [[A:%.*]], [[B:%.*]]
34+
; CHECK: [[TMP2:%.*]] = add nuw i32 [[TMP1]], 14
35+
; CHECK: ret i32 [[TMP2]]
36+
;
37+
%1 = add nuw i32 %a, 14
38+
%2 = add nuw i32 %1, %b
39+
ret i32 %2
40+
}
41+
42+
define i32 @test_customsafe_add_no_nuw(i32 %a, i32 %b) {
43+
; CHECK-LABEL: @test_customsafe_add_no_nuw(
44+
; CHECK: [[TMP1:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
45+
; CHECK: [[TMP2:%.*]] = add i32 [[TMP1]], 14
46+
; CHECK: ret i32 [[TMP2]]
47+
;
48+
%1 = add nuw i32 %a, 14
49+
%2 = add i32 %1, %b
50+
ret i32 %2
51+
}
52+
53+
; Negative checks:
54+
; transfromation is not applied if nsw is set
55+
56+
define i32 @test_customsafe_add_nsw_1(i32 %a, i32 %b) {
57+
; CHECK-LABEL: @test_customsafe_add_nsw_1(
58+
; CHECK-NEXT: [[TMP1:%.*]] = add nsw i32 [[A:%.*]], 14
59+
; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], [[B:%.*]]
60+
; CHECK-NEXT: ret i32 [[TMP2]]
61+
;
62+
%1 = add nsw i32 %a, 14
63+
%2 = add i32 %1, %b
64+
ret i32 %2
65+
}
66+
67+
define i32 @test_customsafe_add_nsw_2(i32 %a, i32 %b) {
68+
; CHECK-LABEL: @test_customsafe_add_nsw_2(
69+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[A:%.*]], 14
70+
; CHECK-NEXT: [[TMP2:%.*]] = add nsw i32 [[TMP1]], [[B:%.*]]
71+
; CHECK-NEXT: ret i32 [[TMP2]]
72+
;
73+
%1 = add i32 %a, 14
74+
%2 = add nsw i32 %1, %b
75+
ret i32 %2
76+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; RUN: igc_opt -igc-custom-safe-opt -S < %s | FileCheck %s
10+
11+
; CustomSafeOpt will try to move emulated addition with constant, from
12+
;
13+
; %1 = shl i32 %a, 4
14+
; %2 = or i32 %1, 14
15+
; %3 = add i32 %2, %b
16+
;
17+
; to
18+
;
19+
; %1 = shl i32 %a, 4
20+
; %2 = add i32 %1, %b
21+
; %3 = add i32 %2, 14
22+
23+
define i32 @test_customsafe_shl(i32 %a, i32 %b) {
24+
; CHECK-LABEL: @test_customsafe_shl(
25+
; CHECK: [[TMP1:%.*]] = shl i32 [[A:%.*]], 4
26+
; CHECK: [[TMP2:%.*]] = add i32 [[TMP1]], [[B:%.*]]
27+
; CHECK: [[TMP3:%.*]] = add i32 [[TMP2]], 14
28+
; CHECK: ret i32 [[TMP3]]
29+
;
30+
%1 = shl i32 %a, 4
31+
%2 = or i32 %1, 14
32+
%3 = add i32 %2, %b
33+
ret i32 %3
34+
}
35+
36+
; Or with multiplication
37+
;
38+
; %1 = mul nuw i64 %a, 6
39+
; %2 = or i64 %1, 1
40+
; %3 = add nuw i64 %2, %b
41+
;
42+
; to
43+
;
44+
; %1 = mul nuw i64 %a, 6
45+
; %2 = add i64 %1, %b
46+
; %3 = add i64 %2, 1
47+
48+
define i64 @test_customsafe_mul(i64 %a, i64 %b) {
49+
; CHECK-LABEL: @test_customsafe_mul(
50+
; CHECK: [[TMP1:%.*]] = mul nuw i64 [[A:%.*]], 6
51+
; CHECK: [[TMP2:%.*]] = add i64 [[TMP1]], [[B:%.*]]
52+
; CHECK: [[TMP3:%.*]] = add i64 [[TMP2]], 1
53+
; CHECK: ret i64 [[TMP3]]
54+
;
55+
%1 = mul nuw i64 %a, 6
56+
%2 = or i64 %1, 1
57+
%3 = add nuw i64 %2, %b
58+
ret i64 %3
59+
}

0 commit comments

Comments
 (0)