Skip to content

Commit 2554a85

Browse files
committed
[CodeGenPrepare][test] Add test for sinking of truncs demonstrating nsw/nuw are dropped
SinkCast creates a new cast with the same type and inputs, which drops the nsw/nuw flags. Reviewed as part of <#89904> but split out so I can land the test separately.
1 parent ed962a6 commit 2554a85

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=riscv64 %s \
3+
; RUN: | FileCheck --check-prefixes=CHECK %s
4+
5+
define i16 @sink_trunc1(i64 %a) {
6+
; CHECK-LABEL: @sink_trunc1(
7+
; CHECK-NEXT: fnend:
8+
; CHECK-NEXT: [[TMP0:%.*]] = trunc i64 [[A:%.*]] to i16
9+
; CHECK-NEXT: ret i16 [[TMP0]]
10+
;
11+
%trunc = trunc i64 %a to i16
12+
br label %fnend
13+
14+
fnend:
15+
ret i16 %trunc
16+
}
17+
18+
; The flags on the original trunc should be preserved.
19+
; FIXME: Flags are currently dropped.
20+
define i16 @sink_trunc2(i64 %a) {
21+
; CHECK-LABEL: @sink_trunc2(
22+
; CHECK-NEXT: fnend:
23+
; CHECK-NEXT: [[TMP0:%.*]] = trunc i64 [[A:%.*]] to i16
24+
; CHECK-NEXT: ret i16 [[TMP0]]
25+
;
26+
%trunc = trunc nuw nsw i64 %a to i16
27+
br label %fnend
28+
29+
fnend:
30+
ret i16 %trunc
31+
}

0 commit comments

Comments
 (0)