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