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