1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
3 ; RUN: opt -passes=instcombine,simplifycfg,instcombine -S < %s | FileCheck %s --check-prefix=EXTRA-PASSES
5 ; Check that code corresponding to the following C function is
6 ; simplified into a single ASR operation:
8 ; int test_asr(int a, int b) {
9 ; return a < 0 ? -(-a - 1 >> b) - 1 : a >> b;
13 define i32 @test_asr(i32 %a, i32 %b) {
14 ; CHECK-LABEL: define i32 @test_asr(
15 ; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
17 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[A]], 0
18 ; CHECK-NEXT: br i1 [[C]], label [[BB2:%.*]], label [[BB3:%.*]]
20 ; CHECK-NEXT: [[NOT2:%.*]] = ashr i32 [[A]], [[B]]
21 ; CHECK-NEXT: br label [[BB4:%.*]]
23 ; CHECK-NEXT: [[E:%.*]] = lshr i32 [[A]], [[B]]
24 ; CHECK-NEXT: br label [[BB4]]
26 ; CHECK-NEXT: [[F:%.*]] = phi i32 [ [[NOT2]], [[BB2]] ], [ [[E]], [[BB3]] ]
27 ; CHECK-NEXT: ret i32 [[F]]
29 ; EXTRA-PASSES-LABEL: define i32 @test_asr(
30 ; EXTRA-PASSES-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
31 ; EXTRA-PASSES-NEXT: entry:
32 ; EXTRA-PASSES-NEXT: [[C1:%.*]] = ashr i32 [[A]], [[B]]
33 ; EXTRA-PASSES-NEXT: ret i32 [[C1]]
36 %c = icmp slt i32 %a, 0
37 br i1 %c, label %bb2, label %bb3
42 %d = ashr i32 %not, %b
44 %not2 = sub i32 %t2, 1
50 %f = phi i32 [ %not2, %bb2 ], [ %e, %bb3 ]