forked from OSchip/llvm-project
[InstCombine] Improve with.overflow intrinsic tests; NFC
- Do not use unnamed values in saddo tests - Add tests for canonicalization of a constant arg0 Patch by Dan Robertson. Differential Revision: https://reviews.llvm.org/D59476 llvm-svn: 356403
This commit is contained in:
parent
1d716acf76
commit
c1d4fc8a62
|
@ -7,96 +7,107 @@ declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32)
|
|||
|
||||
declare { i8, i1 } @llvm.sadd.with.overflow.i8(i8, i8)
|
||||
|
||||
define { i32, i1 } @simple_fold(i32) {
|
||||
define { i32, i1 } @simple_fold(i32 %x) {
|
||||
; CHECK-LABEL: @simple_fold(
|
||||
; CHECK-NEXT: [[TMP2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[TMP0:%.*]], i32 20)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[TMP2]]
|
||||
; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X:%.*]], i32 20)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[TMP1]]
|
||||
;
|
||||
%2 = add nsw i32 %0, 7
|
||||
%3 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %2, i32 13)
|
||||
ret { i32, i1 } %3
|
||||
%a = add nsw i32 %x, 7
|
||||
%b = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 13)
|
||||
ret { i32, i1 } %b
|
||||
}
|
||||
|
||||
define { i32, i1 } @fold_mixed_signs(i32) {
|
||||
define { i32, i1 } @fold_mixed_signs(i32 %x) {
|
||||
; CHECK-LABEL: @fold_mixed_signs(
|
||||
; CHECK-NEXT: [[TMP2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[TMP0:%.*]], i32 6)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[TMP2]]
|
||||
; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X:%.*]], i32 6)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[TMP1]]
|
||||
;
|
||||
%2 = add nsw i32 %0, 13
|
||||
%3 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %2, i32 -7)
|
||||
ret { i32, i1 } %3
|
||||
%a = add nsw i32 %x, 13
|
||||
%b = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 -7)
|
||||
ret { i32, i1 } %b
|
||||
}
|
||||
|
||||
define { i8, i1 } @fold_on_constant_add_no_overflow(i8) {
|
||||
define { i8, i1 } @fold_on_constant_add_no_overflow(i8 %x) {
|
||||
; CHECK-LABEL: @fold_on_constant_add_no_overflow(
|
||||
; CHECK-NEXT: [[TMP2:%.*]] = call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 [[TMP0:%.*]], i8 127)
|
||||
; CHECK-NEXT: ret { i8, i1 } [[TMP2]]
|
||||
; CHECK-NEXT: [[TMP1:%.*]] = call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 [[X:%.*]], i8 127)
|
||||
; CHECK-NEXT: ret { i8, i1 } [[TMP1]]
|
||||
;
|
||||
%2 = add nsw i8 %0, 100
|
||||
%3 = tail call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 %2, i8 27)
|
||||
ret { i8, i1 } %3
|
||||
%a = add nsw i8 %x, 100
|
||||
%b = tail call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 %a, i8 27)
|
||||
ret { i8, i1 } %b
|
||||
}
|
||||
|
||||
define { i8, i1 } @no_fold_on_constant_add_overflow(i8) {
|
||||
define { i8, i1 } @no_fold_on_constant_add_overflow(i8 %x) {
|
||||
; CHECK-LABEL: @no_fold_on_constant_add_overflow(
|
||||
; CHECK-NEXT: [[TMP2:%.*]] = add nsw i8 [[TMP0:%.*]], 100
|
||||
; CHECK-NEXT: [[TMP3:%.*]] = tail call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 [[TMP2]], i8 28)
|
||||
; CHECK-NEXT: ret { i8, i1 } [[TMP3]]
|
||||
; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X:%.*]], 100
|
||||
; CHECK-NEXT: [[B:%.*]] = tail call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 [[A]], i8 28)
|
||||
; CHECK-NEXT: ret { i8, i1 } [[B]]
|
||||
;
|
||||
%2 = add nsw i8 %0, 100
|
||||
%3 = tail call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 %2, i8 28)
|
||||
ret { i8, i1 } %3
|
||||
%a = add nsw i8 %x, 100
|
||||
%b = tail call { i8, i1 } @llvm.sadd.with.overflow.i8(i8 %a, i8 28)
|
||||
ret { i8, i1 } %b
|
||||
}
|
||||
|
||||
define { <2 x i32>, <2 x i1> } @fold_simple_splat_constant(<2 x i32>) {
|
||||
define { <2 x i32>, <2 x i1> } @fold_simple_splat_constant(<2 x i32> %x) {
|
||||
; CHECK-LABEL: @fold_simple_splat_constant(
|
||||
; CHECK-NEXT: [[TMP2:%.*]] = call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> [[TMP0:%.*]], <2 x i32> <i32 42, i32 42>)
|
||||
; CHECK-NEXT: ret { <2 x i32>, <2 x i1> } [[TMP2]]
|
||||
; CHECK-NEXT: [[TMP1:%.*]] = call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> [[X:%.*]], <2 x i32> <i32 42, i32 42>)
|
||||
; CHECK-NEXT: ret { <2 x i32>, <2 x i1> } [[TMP1]]
|
||||
;
|
||||
%2 = add nsw <2 x i32> %0, <i32 12, i32 12>
|
||||
%3 = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> %2, <2 x i32> <i32 30, i32 30>)
|
||||
ret { <2 x i32>, <2 x i1> } %3
|
||||
%a = add nsw <2 x i32> %x, <i32 12, i32 12>
|
||||
%b = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> %a, <2 x i32> <i32 30, i32 30>)
|
||||
ret { <2 x i32>, <2 x i1> } %b
|
||||
}
|
||||
|
||||
define { <2 x i32>, <2 x i1> } @no_fold_splat_undef_constant(<2 x i32>) {
|
||||
define { <2 x i32>, <2 x i1> } @no_fold_splat_undef_constant(<2 x i32> %x) {
|
||||
; CHECK-LABEL: @no_fold_splat_undef_constant(
|
||||
; CHECK-NEXT: [[TMP2:%.*]] = add nsw <2 x i32> [[TMP0:%.*]], <i32 12, i32 undef>
|
||||
; CHECK-NEXT: [[TMP3:%.*]] = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> [[TMP2]], <2 x i32> <i32 30, i32 30>)
|
||||
; CHECK-NEXT: ret { <2 x i32>, <2 x i1> } [[TMP3]]
|
||||
; CHECK-NEXT: [[A:%.*]] = add nsw <2 x i32> [[X:%.*]], <i32 12, i32 undef>
|
||||
; CHECK-NEXT: [[B:%.*]] = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> [[A]], <2 x i32> <i32 30, i32 30>)
|
||||
; CHECK-NEXT: ret { <2 x i32>, <2 x i1> } [[B]]
|
||||
;
|
||||
%2 = add nsw <2 x i32> %0, <i32 12, i32 undef>
|
||||
%3 = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> %2, <2 x i32> <i32 30, i32 30>)
|
||||
ret { <2 x i32>, <2 x i1> } %3
|
||||
%a = add nsw <2 x i32> %x, <i32 12, i32 undef>
|
||||
%b = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> %a, <2 x i32> <i32 30, i32 30>)
|
||||
ret { <2 x i32>, <2 x i1> } %b
|
||||
}
|
||||
|
||||
define { <2 x i32>, <2 x i1> } @no_fold_splat_not_constant(<2 x i32>, <2 x i32>) {
|
||||
define { <2 x i32>, <2 x i1> } @no_fold_splat_not_constant(<2 x i32> %x, <2 x i32> %y) {
|
||||
; CHECK-LABEL: @no_fold_splat_not_constant(
|
||||
; CHECK-NEXT: [[TMP3:%.*]] = add nsw <2 x i32> [[TMP0:%.*]], [[TMP1:%.*]]
|
||||
; CHECK-NEXT: [[TMP4:%.*]] = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> [[TMP3]], <2 x i32> <i32 30, i32 30>)
|
||||
; CHECK-NEXT: ret { <2 x i32>, <2 x i1> } [[TMP4]]
|
||||
; CHECK-NEXT: [[A:%.*]] = add nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
|
||||
; CHECK-NEXT: [[B:%.*]] = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> [[A]], <2 x i32> <i32 30, i32 30>)
|
||||
; CHECK-NEXT: ret { <2 x i32>, <2 x i1> } [[B]]
|
||||
;
|
||||
%3 = add nsw <2 x i32> %0, %1
|
||||
%4 = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> %3, <2 x i32> <i32 30, i32 30>)
|
||||
ret { <2 x i32>, <2 x i1> } %4
|
||||
%a = add nsw <2 x i32> %x, %y
|
||||
%b = tail call { <2 x i32>, <2 x i1> } @llvm.sadd.with.overflow.v2i32(<2 x i32> %a, <2 x i32> <i32 30, i32 30>)
|
||||
ret { <2 x i32>, <2 x i1> } %b
|
||||
}
|
||||
|
||||
define { i32, i1 } @fold_nuwnsw(i32) {
|
||||
define { i32, i1 } @fold_nuwnsw(i32 %x) {
|
||||
; CHECK-LABEL: @fold_nuwnsw(
|
||||
; CHECK-NEXT: [[TMP2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[TMP0:%.*]], i32 42)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[TMP2]]
|
||||
; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X:%.*]], i32 42)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[TMP1]]
|
||||
;
|
||||
%2 = add nuw nsw i32 %0, 12
|
||||
%3 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %2, i32 30)
|
||||
ret { i32, i1 } %3
|
||||
%a = add nuw nsw i32 %x, 12
|
||||
%b = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 30)
|
||||
ret { i32, i1 } %b
|
||||
}
|
||||
|
||||
define { i32, i1 } @no_fold_nuw(i32) {
|
||||
define { i32, i1 } @no_fold_nuw(i32 %x) {
|
||||
; CHECK-LABEL: @no_fold_nuw(
|
||||
; CHECK-NEXT: [[TMP2:%.*]] = add nuw i32 [[TMP0:%.*]], 12
|
||||
; CHECK-NEXT: [[TMP3:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[TMP2]], i32 30)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[TMP3]]
|
||||
; CHECK-NEXT: [[A:%.*]] = add nuw i32 [[X:%.*]], 12
|
||||
; CHECK-NEXT: [[B:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[A]], i32 30)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[B]]
|
||||
;
|
||||
%2 = add nuw i32 %0, 12
|
||||
%3 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %2, i32 30)
|
||||
ret { i32, i1 } %3
|
||||
%a = add nuw i32 %x, 12
|
||||
%b = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 30)
|
||||
ret { i32, i1 } %b
|
||||
}
|
||||
|
||||
define { i32, i1 } @no_fold_wrapped_add(i32 %x) {
|
||||
; CHECK-LABEL: @no_fold_wrapped_add(
|
||||
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 12
|
||||
; CHECK-NEXT: [[B:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[A]], i32 30)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[B]]
|
||||
;
|
||||
%a = add i32 %x, 12
|
||||
%b = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 30, i32 %a)
|
||||
ret { i32, i1 } %b
|
||||
}
|
||||
|
|
|
@ -468,3 +468,57 @@ define i1 @uadd_res_ult_const_minus_one(i32 %x, i1* %p) nounwind {
|
|||
%d = icmp ult i32 %c, -1
|
||||
ret i1 %d
|
||||
}
|
||||
|
||||
define { i32, i1 } @sadd_canonicalize_constant_arg0(i32 %x) nounwind {
|
||||
; CHECK-LABEL: @sadd_canonicalize_constant_arg0(
|
||||
; CHECK-NEXT: [[A:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X:%.*]], i32 42)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[A]]
|
||||
;
|
||||
%a = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 42, i32 %x)
|
||||
ret { i32, i1 } %a
|
||||
}
|
||||
|
||||
define { i32, i1 } @uadd_canonicalize_constant_arg0(i32 %x) nounwind {
|
||||
; CHECK-LABEL: @uadd_canonicalize_constant_arg0(
|
||||
; CHECK-NEXT: [[A:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[X:%.*]], i32 42)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[A]]
|
||||
;
|
||||
%a = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 42, i32 %x)
|
||||
ret { i32, i1 } %a
|
||||
}
|
||||
|
||||
define { i32, i1 } @ssub_no_canonicalize_constant_arg0(i32 %x) nounwind {
|
||||
; CHECK-LABEL: @ssub_no_canonicalize_constant_arg0(
|
||||
; CHECK-NEXT: [[A:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 42, i32 [[X:%.*]])
|
||||
; CHECK-NEXT: ret { i32, i1 } [[A]]
|
||||
;
|
||||
%a = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 42, i32 %x)
|
||||
ret { i32, i1 } %a
|
||||
}
|
||||
|
||||
define { i32, i1 } @usub_no_canonicalize_constant_arg0(i32 %x) nounwind {
|
||||
; CHECK-LABEL: @usub_no_canonicalize_constant_arg0(
|
||||
; CHECK-NEXT: [[A:%.*]] = call { i32, i1 } @llvm.usub.with.overflow.i32(i32 42, i32 [[X:%.*]])
|
||||
; CHECK-NEXT: ret { i32, i1 } [[A]]
|
||||
;
|
||||
%a = call { i32, i1 } @llvm.usub.with.overflow.i32(i32 42, i32 %x)
|
||||
ret { i32, i1 } %a
|
||||
}
|
||||
|
||||
define { i32, i1 } @smul_canonicalize_constant_arg0(i32 %x) nounwind {
|
||||
; CHECK-LABEL: @smul_canonicalize_constant_arg0(
|
||||
; CHECK-NEXT: [[A:%.*]] = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 [[X:%.*]], i32 42)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[A]]
|
||||
;
|
||||
%a = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 42, i32 %x)
|
||||
ret { i32, i1 } %a
|
||||
}
|
||||
|
||||
define { i32, i1 } @umul_canonicalize_constant_arg0(i32 %x) nounwind {
|
||||
; CHECK-LABEL: @umul_canonicalize_constant_arg0(
|
||||
; CHECK-NEXT: [[A:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[X:%.*]], i32 42)
|
||||
; CHECK-NEXT: ret { i32, i1 } [[A]]
|
||||
;
|
||||
%a = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 42, i32 %x)
|
||||
ret { i32, i1 } %a
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue