summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-02-26 15:18:44 +0000
committerSanjay Patel <spatel@rotateright.com>2019-02-26 15:18:44 +0000
commitc9af54bb554fe459795fe61eed169528e00b0910 (patch)
tree3a53eba4db55624cde72ec30349b5564f93bc59f /llvm/test
parent0d76dc285c17c3e87994e46e4e0dc8383c755e4b (diff)
downloadbcm5719-llvm-c9af54bb554fe459795fe61eed169528e00b0910.tar.gz
bcm5719-llvm-c9af54bb554fe459795fe61eed169528e00b0910.zip
[InstCombine] add more tests for saturated add; NFC
llvm-svn: 354886
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Transforms/InstCombine/saturating-add-sub.ll134
1 files changed, 134 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/saturating-add-sub.ll b/llvm/test/Transforms/InstCombine/saturating-add-sub.ll
index 961a9f8ce8e..8e171485514 100644
--- a/llvm/test/Transforms/InstCombine/saturating-add-sub.ll
+++ b/llvm/test/Transforms/InstCombine/saturating-add-sub.ll
@@ -931,6 +931,140 @@ define i32 @uadd_sat_not_commute_select_ugt_commute_add(i32 %x, i32 %y) {
ret i32 %r
}
+; The add may include a 'not' op rather than the cmp.
+
+define i32 @uadd_sat_not(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_not(
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[A:%.*]] = add i32 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %notx, %y
+ %c = icmp ult i32 %x, %y
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
+define i32 @uadd_sat_not_commute_add(i32 %xp, i32 %yp) {
+; CHECK-LABEL: @uadd_sat_not_commute_add(
+; CHECK-NEXT: [[X:%.*]] = srem i32 42, [[XP:%.*]]
+; CHECK-NEXT: [[Y:%.*]] = urem i32 42, [[YP:%.*]]
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X]], -1
+; CHECK-NEXT: [[A:%.*]] = add nsw i32 [[Y]], [[NOTX]]
+; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %x = srem i32 42, %xp ; thwart complexity-based-canonicalization
+ %y = urem i32 42, %yp ; thwart complexity-based-canonicalization
+ %notx = xor i32 %x, -1
+ %a = add i32 %y, %notx
+ %c = icmp ult i32 %x, %y
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
+define i32 @uadd_sat_not_ugt(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_not_ugt(
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[A:%.*]] = add i32 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[Y]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %notx, %y
+ %c = icmp ugt i32 %y, %x
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
+define <2 x i32> @uadd_sat_not_ugt_commute_add(<2 x i32> %x, <2 x i32> %yp) {
+; CHECK-LABEL: @uadd_sat_not_ugt_commute_add(
+; CHECK-NEXT: [[Y:%.*]] = sdiv <2 x i32> [[YP:%.*]], <i32 2442, i32 4242>
+; CHECK-NEXT: [[NOTX:%.*]] = xor <2 x i32> [[X:%.*]], <i32 -1, i32 -1>
+; CHECK-NEXT: [[A:%.*]] = add <2 x i32> [[Y]], [[NOTX]]
+; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[Y]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C]], <2 x i32> <i32 -1, i32 -1>, <2 x i32> [[A]]
+; CHECK-NEXT: ret <2 x i32> [[R]]
+;
+ %y = sdiv <2 x i32> %yp, <i32 2442, i32 4242> ; thwart complexity-based-canonicalization
+ %notx = xor <2 x i32> %x, <i32 -1, i32 -1>
+ %a = add <2 x i32> %y, %notx
+ %c = icmp ugt <2 x i32> %y, %x
+ %r = select <2 x i1> %c, <2 x i32> <i32 -1, i32 -1>, <2 x i32> %a
+ ret <2 x i32> %r
+}
+
+define i32 @uadd_sat_not_commute_select(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_not_commute_select(
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[A:%.*]] = add i32 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[Y]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 [[A]], i32 -1
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %notx, %y
+ %c = icmp ult i32 %y, %x
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}
+
+define i32 @uadd_sat_not_commute_select_commute_add(i32 %x, i32 %yp) {
+; CHECK-LABEL: @uadd_sat_not_commute_select_commute_add(
+; CHECK-NEXT: [[Y:%.*]] = sdiv i32 42, [[YP:%.*]]
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[A:%.*]] = add i32 [[Y]], [[NOTX]]
+; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[Y]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 [[A]], i32 -1
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %y = sdiv i32 42, %yp ; thwart complexity-based-canonicalization
+ %notx = xor i32 %x, -1
+ %a = add i32 %y, %notx
+ %c = icmp ult i32 %y, %x
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}
+
+define <2 x i32> @uadd_sat_not_commute_select_ugt(<2 x i32> %xp, <2 x i32> %yp) {
+; CHECK-LABEL: @uadd_sat_not_commute_select_ugt(
+; CHECK-NEXT: [[X:%.*]] = urem <2 x i32> <i32 42, i32 -42>, [[XP:%.*]]
+; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> <i32 12, i32 412>, [[YP:%.*]]
+; CHECK-NEXT: [[NOTX:%.*]] = xor <2 x i32> [[X]], <i32 -1, i32 -1>
+; CHECK-NEXT: [[A:%.*]] = add <2 x i32> [[Y]], [[NOTX]]
+; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[X]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C]], <2 x i32> [[A]], <2 x i32> <i32 -1, i32 -1>
+; CHECK-NEXT: ret <2 x i32> [[R]]
+;
+ %x = urem <2 x i32> <i32 42, i32 -42>, %xp ; thwart complexity-based-canonicalization
+ %y = srem <2 x i32> <i32 12, i32 412>, %yp ; thwart complexity-based-canonicalization
+ %notx = xor <2 x i32> %x, <i32 -1, i32 -1>
+ %a = add <2 x i32> %y, %notx
+ %c = icmp ugt <2 x i32> %x, %y
+ %r = select <2 x i1> %c, <2 x i32> %a, <2 x i32> <i32 -1, i32 -1>
+ ret <2 x i32> %r
+}
+
+define i32 @uadd_sat_not_commute_select_ugt_commute_add(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_not_commute_select_ugt_commute_add(
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[A:%.*]] = add i32 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 [[A]], i32 -1
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %notx, %y
+ %c = icmp ugt i32 %x, %y
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}
+
define i32 @uadd_sat_constant(i32 %x) {
; CHECK-LABEL: @uadd_sat_constant(
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 42
OpenPOWER on IntegriCloud