forked from OSchip/llvm-project
[ValueTracking] Add abs intrinsics support to computeConstantRange()
Implementation is the same as for SPF_ABS.
This commit is contained in:
parent
6446c11840
commit
eba5f5f798
|
@ -6441,6 +6441,14 @@ static void setLimitsForIntrinsic(const IntrinsicInst &II, APInt &Lower,
|
|||
llvm_unreachable("Must be min/max intrinsic");
|
||||
}
|
||||
break;
|
||||
case Intrinsic::abs:
|
||||
// If abs of SIGNED_MIN is poison, then the result is [0..SIGNED_MAX],
|
||||
// otherwise it is [0..SIGNED_MIN], as -SIGNED_MIN == SIGNED_MIN.
|
||||
if (match(II.getOperand(1), m_One()))
|
||||
Upper = APInt::getSignedMaxValue(Width) + 1;
|
||||
else
|
||||
Upper = APInt::getSignedMinValue(Width) + 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ define i32 @abs_signbits(i30 %x) {
|
|||
; CHECK-LABEL: @abs_signbits(
|
||||
; CHECK-NEXT: [[EXT:%.*]] = sext i30 [[X:%.*]] to i32
|
||||
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[EXT]], i1 false)
|
||||
; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[ABS]], 1
|
||||
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[ABS]], 1
|
||||
; CHECK-NEXT: ret i32 [[ADD]]
|
||||
;
|
||||
%ext = sext i30 %x to i32
|
||||
|
@ -76,7 +76,7 @@ define <4 x i32> @abs_signbits_vec(<4 x i30> %x) {
|
|||
; CHECK-LABEL: @abs_signbits_vec(
|
||||
; CHECK-NEXT: [[EXT:%.*]] = sext <4 x i30> [[X:%.*]] to <4 x i32>
|
||||
; CHECK-NEXT: [[ABS:%.*]] = call <4 x i32> @llvm.abs.v4i32(<4 x i32> [[EXT]], i1 false)
|
||||
; CHECK-NEXT: [[ADD:%.*]] = add nsw <4 x i32> [[ABS]], <i32 1, i32 1, i32 1, i32 1>
|
||||
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw <4 x i32> [[ABS]], <i32 1, i32 1, i32 1, i32 1>
|
||||
; CHECK-NEXT: ret <4 x i32> [[ADD]]
|
||||
;
|
||||
%ext = sext <4 x i30> %x to <4 x i32>
|
||||
|
|
|
@ -186,9 +186,7 @@ define <4 x i1> @abs_known_not_int_min_vec(<4 x i32> %x) {
|
|||
; If it's >= 0 it should be >= -1 as well.
|
||||
define i1 @abs_nsw_sge_neg(i32 %x) {
|
||||
; CHECK-LABEL: @abs_nsw_sge_neg(
|
||||
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 true)
|
||||
; CHECK-NEXT: [[C:%.*]] = icmp sge i32 [[ABS]], -1
|
||||
; CHECK-NEXT: ret i1 [[C]]
|
||||
; CHECK-NEXT: ret i1 true
|
||||
;
|
||||
%abs = call i32 @llvm.abs.i32(i32 %x, i1 true)
|
||||
%c = icmp sge i32 %abs, -1
|
||||
|
@ -197,9 +195,7 @@ define i1 @abs_nsw_sge_neg(i32 %x) {
|
|||
|
||||
define i1 @abs_ule_int_min(i8 %x) {
|
||||
; CHECK-LABEL: @abs_ule_int_min(
|
||||
; CHECK-NEXT: [[ABS:%.*]] = call i8 @llvm.abs.i8(i8 [[X:%.*]], i1 false)
|
||||
; CHECK-NEXT: [[C:%.*]] = icmp ule i8 [[ABS]], -128
|
||||
; CHECK-NEXT: ret i1 [[C]]
|
||||
; CHECK-NEXT: ret i1 true
|
||||
;
|
||||
%abs = call i8 @llvm.abs.i8(i8 %x, i1 false)
|
||||
%c = icmp ule i8 %abs, 128
|
||||
|
|
Loading…
Reference in New Issue