1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
4 ; This looks like a normal sign extension, but it's not.
5 ; This comes up in JPEG decoding. This check is really unpredictable,
6 ; so it is likely beneficial to avoid the branch.
8 define i32 @extend_value(i32 %storage, i32 %nbits) {
9 ; CHECK-LABEL: @extend_value(
11 ; CHECK-NEXT: [[SKIPNBITS:%.*]] = sub i32 32, [[NBITS:%.*]]
12 ; CHECK-NEXT: [[VALUE:%.*]] = lshr i32 [[STORAGE:%.*]], [[SKIPNBITS]]
13 ; CHECK-NEXT: [[SHOULDEXTEND:%.*]] = icmp sgt i32 [[STORAGE]], -1
14 ; CHECK-NEXT: [[HIGHBITMASK:%.*]] = shl nsw i32 -1, [[NBITS]]
15 ; CHECK-NEXT: [[HIGHBITMASKPLUSONE:%.*]] = add nsw i32 [[HIGHBITMASK]], 1
16 ; CHECK-NEXT: [[EXTENDED:%.*]] = add i32 [[HIGHBITMASKPLUSONE]], [[VALUE]]
17 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[SHOULDEXTEND]], i32 [[EXTENDED]], i32 [[VALUE]]
18 ; CHECK-NEXT: ret i32 [[RES]]
21 %skipnbits = sub i32 32, %nbits
22 %value = lshr i32 %storage, %skipnbits
23 %shouldextend = icmp sgt i32 %storage, -1
24 br i1 %shouldextend, label %extend, label %end
27 %highbitmask = shl nsw i32 -1, %nbits
28 %highbitmaskplusone = add nsw i32 %highbitmask, 1
29 %extended = add i32 %highbitmaskplusone, %value
32 end: ; preds = %extend, %bb
33 %res = phi i32 [ %extended, %extend ], [ %value, %bb ]