xref: /llvm-project/llvm/test/Transforms/CodeGenPrepare/X86/pr118172.ll (revision 6568ceb9fa1c49383b2fa102a04fd8fd3af01491)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
3
4; Make sure the nsw flag is dropped when the load ext is combined.
5define i32 @simplify_load_ext_drop_trunc_nsw(ptr %p) {
6; CHECK-LABEL: define i32 @simplify_load_ext_drop_trunc_nsw(
7; CHECK-SAME: ptr [[P:%.*]]) {
8; CHECK-NEXT:  [[ENTRY:.*:]]
9; CHECK-NEXT:    [[X:%.*]] = load i32, ptr [[P]], align 4
10; CHECK-NEXT:    [[TMP0:%.*]] = and i32 [[X]], 255
11; CHECK-NEXT:    [[TRUNC:%.*]] = trunc i32 [[TMP0]] to i8
12; CHECK-NEXT:    [[EXT1:%.*]] = sext i8 [[TRUNC]] to i16
13; CHECK-NEXT:    call void @use(i32 [[TMP0]])
14; CHECK-NEXT:    [[EXT2:%.*]] = zext i16 [[EXT1]] to i32
15; CHECK-NEXT:    ret i32 [[EXT2]]
16;
17entry:
18  %x = load i32, ptr %p, align 4
19  %trunc = trunc nsw i32 %x to i8
20  %ext1 = sext i8 %trunc to i16
21  %conv2 = and i32 %x, 255
22  call void @use(i32 %conv2)
23  %ext2 = zext i16 %ext1 to i32
24  ret i32 %ext2
25}
26
27; Make sure the nsw flag is dropped when the load ext is combined.
28define i32 @simplify_load_ext_drop_shl_nsw(ptr %p) {
29; CHECK-LABEL: define i32 @simplify_load_ext_drop_shl_nsw(
30; CHECK-SAME: ptr [[P:%.*]]) {
31; CHECK-NEXT:  [[ENTRY:.*:]]
32; CHECK-NEXT:    [[X:%.*]] = load i32, ptr [[P]], align 4
33; CHECK-NEXT:    [[TMP0:%.*]] = and i32 [[X]], 255
34; CHECK-NEXT:    [[SHL:%.*]] = shl i32 [[TMP0]], 24
35; CHECK-NEXT:    call void @use(i32 [[TMP0]])
36; CHECK-NEXT:    ret i32 [[SHL]]
37;
38entry:
39  %x = load i32, ptr %p, align 4
40  %shl = shl nsw i32 %x, 24
41  %conv2 = and i32 %x, 255
42  call void @use(i32 %conv2)
43  ret i32 %shl
44}
45
46define i32 @simplify_load_ext_keep_trunc_nuw(ptr %p) {
47; CHECK-LABEL: define i32 @simplify_load_ext_keep_trunc_nuw(
48; CHECK-SAME: ptr [[P:%.*]]) {
49; CHECK-NEXT:  [[ENTRY:.*:]]
50; CHECK-NEXT:    [[X:%.*]] = load i32, ptr [[P]], align 4
51; CHECK-NEXT:    [[TMP0:%.*]] = and i32 [[X]], 255
52; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw i32 [[TMP0]] to i8
53; CHECK-NEXT:    [[EXT1:%.*]] = sext i8 [[TRUNC]] to i16
54; CHECK-NEXT:    call void @use(i32 [[TMP0]])
55; CHECK-NEXT:    [[EXT2:%.*]] = zext i16 [[EXT1]] to i32
56; CHECK-NEXT:    ret i32 [[EXT2]]
57;
58entry:
59  %x = load i32, ptr %p, align 4
60  %trunc = trunc nuw i32 %x to i8
61  %ext1 = sext i8 %trunc to i16
62  %conv2 = and i32 %x, 255
63  call void @use(i32 %conv2)
64  %ext2 = zext i16 %ext1 to i32
65  ret i32 %ext2
66}
67
68define i32 @simplify_load_ext_drop_shl_nuw(ptr %p) {
69; CHECK-LABEL: define i32 @simplify_load_ext_drop_shl_nuw(
70; CHECK-SAME: ptr [[P:%.*]]) {
71; CHECK-NEXT:  [[ENTRY:.*:]]
72; CHECK-NEXT:    [[X:%.*]] = load i32, ptr [[P]], align 4
73; CHECK-NEXT:    [[TMP0:%.*]] = and i32 [[X]], 255
74; CHECK-NEXT:    [[SHL:%.*]] = shl nuw i32 [[TMP0]], 24
75; CHECK-NEXT:    call void @use(i32 [[TMP0]])
76; CHECK-NEXT:    ret i32 [[SHL]]
77;
78entry:
79  %x = load i32, ptr %p, align 4
80  %shl = shl nuw i32 %x, 24
81  %conv2 = and i32 %x, 255
82  call void @use(i32 %conv2)
83  ret i32 %shl
84}
85
86declare void @use(i32)
87