[llvm] 1d25d07 - [NFC][InstCombine] Add tests for negation of old-style [n]abs, select-of-op-vs-negation-of-op

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 11:48:05 PDT 2020


Author: Roman Lebedev
Date: 2020-08-05T21:47:30+03:00
New Revision: 1d25d0734a15d03f1356735719e04a517a1a8a96

URL: https://github.com/llvm/llvm-project/commit/1d25d0734a15d03f1356735719e04a517a1a8a96
DIFF: https://github.com/llvm/llvm-project/commit/1d25d0734a15d03f1356735719e04a517a1a8a96.diff

LOG: [NFC][InstCombine] Add tests for negation of old-style [n]abs, select-of-op-vs-negation-of-op

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/sub-of-negatible.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
index f1f0609c924a8..d4b2de3db4d32 100644
--- a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
+++ b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
@@ -1136,3 +1136,67 @@ define i8 @negate_add_with_single_negatible_operand_non_negation(i8 %x, i8 %y) {
   %t1 = sub i8 %y, %t0
   ret i8 %t1
 }
+
+; abs/nabs can be negated
+define i8 @negate_abs(i8 %x, i8 %y) {
+; CHECK-LABEL: @negate_abs(
+; CHECK-NEXT:    [[T0:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT:    call void @use8(i8 [[T0]])
+; CHECK-NEXT:    [[T1:%.*]] = icmp slt i8 [[X]], 0
+; CHECK-NEXT:    [[TMP1:%.*]] = select i1 [[T1]], i8 [[X]], i8 [[T0]], !prof !0
+; CHECK-NEXT:    [[T3:%.*]] = add i8 [[TMP1]], [[Y:%.*]]
+; CHECK-NEXT:    ret i8 [[T3]]
+;
+  %t0 = sub i8 0, %x
+  call void @use8(i8 %t0)
+  %t1 = icmp slt i8 %x, 0
+  %t2 = select i1 %t1, i8 %t0, i8 %x, !prof !0
+  %t3 = sub i8 %y, %t2
+  ret i8 %t3
+}
+define i8 @negate_nabs(i8 %x, i8 %y) {
+; CHECK-LABEL: @negate_nabs(
+; CHECK-NEXT:    [[T0:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT:    call void @use8(i8 [[T0]])
+; CHECK-NEXT:    [[T1:%.*]] = icmp slt i8 [[X]], 0
+; CHECK-NEXT:    [[TMP1:%.*]] = select i1 [[T1]], i8 [[T0]], i8 [[X]], !prof !0
+; CHECK-NEXT:    [[T3:%.*]] = add i8 [[TMP1]], [[Y:%.*]]
+; CHECK-NEXT:    ret i8 [[T3]]
+;
+  %t0 = sub i8 0, %x
+  call void @use8(i8 %t0)
+  %t1 = icmp slt i8 %x, 0
+  %t2 = select i1 %t1, i8 %x, i8 %t0, !prof !0
+  %t3 = sub i8 %y, %t2
+  ret i8 %t3
+}
+
+; And in general, if hands of select are known to be negation of each other,
+; we can negate the select
+define i8 @negate_select_of_op_vs_negated_op(i8 %x, i8 %y, i1 %c) {
+; CHECK-LABEL: @negate_select_of_op_vs_negated_op(
+; CHECK-NEXT:    [[T0:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT:    call void @use8(i8 [[T0]])
+; CHECK-NEXT:    [[T1:%.*]] = select i1 [[C:%.*]], i8 [[T0]], i8 [[X]], !prof !0
+; CHECK-NEXT:    [[T2:%.*]] = sub i8 [[Y:%.*]], [[T1]]
+; CHECK-NEXT:    ret i8 [[T2]]
+;
+  %t0 = sub i8 0, %x
+  call void @use8(i8 %t0)
+  %t1 = select i1 %c, i8 %t0, i8 %x, !prof !0
+  %t2 = sub i8 %y, %t1
+  ret i8 %t2
+}
+define i8 @dont_negate_ordinary_select(i8 %x, i8 %y, i8 %z, i1 %c) {
+; CHECK-LABEL: @dont_negate_ordinary_select(
+; CHECK-NEXT:    [[T0:%.*]] = select i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]
+; CHECK-NEXT:    [[T1:%.*]] = sub i8 [[Z:%.*]], [[T0]]
+; CHECK-NEXT:    ret i8 [[T1]]
+;
+  %t0 = select i1 %c, i8 %x, i8 %y
+  %t1 = sub i8 %z, %t0
+  ret i8 %t1
+}
+
+; CHECK: !0 = !{!"branch_weights", i32 40, i32 1}
+!0 = !{!"branch_weights", i32 40, i32 1}


        


More information about the llvm-commits mailing list