1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
4 ; Reduced from arm_abs_q31() from CMSIS DSP suite.
5 ; https://reviews.llvm.org/D65148#1629010
7 define i32 @abs_with_clamp(i32 %arg) {
8 ; CHECK-LABEL: @abs_with_clamp(
10 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[ARG:%.*]], 0
11 ; CHECK-NEXT: [[IS_INT_MIN:%.*]] = icmp eq i32 [[ARG]], -2147483648
12 ; CHECK-NEXT: [[NEGATED:%.*]] = sub nsw i32 0, [[ARG]]
13 ; CHECK-NEXT: [[ABS:%.*]] = select i1 [[IS_INT_MIN]], i32 2147483647, i32 [[NEGATED]]
14 ; CHECK-NEXT: [[TMP6:%.*]] = select i1 [[IS_POSITIVE]], i32 [[ARG]], i32 [[ABS]]
15 ; CHECK-NEXT: ret i32 [[TMP6]]
18 %is_positive = icmp sgt i32 %arg, 0
19 br i1 %is_positive, label %end, label %negative
21 negative: ; preds = %begin
22 %is_int_min = icmp eq i32 %arg, -2147483648
23 %negated = sub nsw i32 0, %arg
24 %abs = select i1 %is_int_min, i32 2147483647, i32 %negated
27 end: ; preds = %negative, %begin
28 %tmp6 = phi i32 [ %arg, %begin ], [ %abs, %negative ]