• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -instsimplify -S | FileCheck %s
2
3; PR8862
4
5define i32 @shift1(i32 %A, i32 %B) {
6; CHECK-LABEL: @shift1(
7; CHECK-NEXT:    ret i32 %A
8;
9  %C = lshr exact i32 %A, %B
10  %D = shl nuw i32 %C, %B
11  ret i32 %D
12}
13
14define i32 @shift2(i32 %A, i32 %B) {
15; CHECK-LABEL: @shift2(
16; CHECK-NEXT:    [[C:%.*]] = lshr i32 %A, %B
17; CHECK-NEXT:    [[D:%.*]] = shl nuw i32 [[C]], %B
18; CHECK-NEXT:    ret i32 [[D]]
19;
20  %C = lshr i32 %A, %B
21  %D = shl nuw i32 %C, %B
22  ret i32 %D
23}
24
25define i32 @shift3(i32 %A, i32 %B) {
26; CHECK-LABEL: @shift3(
27; CHECK-NEXT:    ret i32 %A
28;
29  %C = ashr exact i32 %A, %B
30  %D = shl nuw i32 %C, %B
31  ret i32 %D
32}
33
34define i32 @shift4(i32 %A, i32 %B) {
35; CHECK-LABEL: @shift4(
36; CHECK-NEXT:    ret i32 %A
37;
38  %C = shl nuw i32 %A, %B
39  %D = lshr i32 %C, %B
40  ret i32 %D
41}
42
43define i32 @shift5(i32 %A, i32 %B) {
44; CHECK-LABEL: @shift5(
45; CHECK-NEXT:    ret i32 %A
46;
47  %C = shl nsw i32 %A, %B
48  %D = ashr i32 %C, %B
49  ret i32 %D
50}
51
52define i32 @div1(i32 %V) {
53; CHECK-LABEL: @div1(
54; CHECK-NEXT:    ret i32 0
55;
56  %A = udiv i32 %V, -2147483648
57  %B = udiv i32 %A, -2147483648
58  ret i32 %B
59}
60
61define i32 @div2(i32 %V) {
62; CHECK-LABEL: @div2(
63; CHECK-NEXT:    ret i32 0
64;
65  %A = sdiv i32 %V, -1
66  %B = sdiv i32 %A, -2147483648
67  ret i32 %B
68}
69
70