[InstCombine] Signed saturation patterns
[llvm-core.git] / test / Transforms / InstCombine / icmp_sdiv_with_and_without_range.ll
blob174c4b906e31b349d0245e6d69547a2ea6d44586
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
4 ; Test that presence of range does not cause unprofitable transforms with bit
5 ; arithmetics, and instcombine behaves exactly the same as without the range.
7 define i1 @without_range(i32* %A) {
8 ; CHECK-LABEL: @without_range(
9 ; CHECK-NEXT:    [[A_VAL:%.*]] = load i32, i32* [[A:%.*]], align 8
10 ; CHECK-NEXT:    [[C:%.*]] = icmp slt i32 [[A_VAL]], 2
11 ; CHECK-NEXT:    ret i1 [[C]]
13   %A.val = load i32, i32* %A, align 8
14   %B = sdiv i32 %A.val, 2
15   %C = icmp sge i32 0, %B
16   ret i1 %C
19 define i1 @with_range(i32* %A) {
20 ; CHECK-LABEL: @with_range(
21 ; CHECK-NEXT:    [[A_VAL:%.*]] = load i32, i32* [[A:%.*]], align 8, !range !0
22 ; CHECK-NEXT:    [[B_MASK:%.*]] = and i32 [[A_VAL]], 2147483646
23 ; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[B_MASK]], 0
24 ; CHECK-NEXT:    ret i1 [[C]]
26   %A.val = load i32, i32* %A, align 8, !range !0
27   %B = sdiv i32 %A.val, 2
28   %C = icmp sge i32 0, %B
29   ret i1 %C
32 !0 = !{i32 0, i32 2147483647}