ret i32 %sel
}
+; The comparison is not with the same value we take abs() of, so this isn't the pattern.
+define i32 @select_abs_of_abs_eq_wrong(i32 %x, i32 %y) {
+; CHECK-LABEL: @select_abs_of_abs_eq_wrong(
+; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
+; CHECK-NEXT: ret i32 [[ABS]]
+;
+ %abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
+ %neg = sub i32 0, %abs
+ %cmp = icmp eq i32 %y, 0 ; not %x
+ %sel = select i1 %cmp, i32 %neg, i32 %abs
+ ret i32 %sel
+}
+
define i32 @select_abs_of_abs_ne(i32 %x) {
; CHECK-LABEL: @select_abs_of_abs_ne(
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
ret i32 %sel
}
+; The comparison is not with the same value we take abs() of, so this isn't the pattern.
+define i32 @select_nabs_of_abs_eq_wrong(i32 %x, i32 %y) {
+; CHECK-LABEL: @select_nabs_of_abs_eq_wrong(
+; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
+; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[ABS]]
+; CHECK-NEXT: ret i32 [[NEG]]
+;
+ %abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
+ %neg = sub i32 0, %abs
+ %cmp = icmp eq i32 %y, 0
+ %sel = select i1 %cmp, i32 %abs, i32 %neg
+ ret i32 %sel
+}
+
define i32 @select_nabs_of_abs_ne(i32 %x) {
; CHECK-LABEL: @select_nabs_of_abs_ne(
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)