[llvm] r336822 - [InstSimplify] add/move tests for add folds; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 11 09:52:18 PDT 2018


Author: spatel
Date: Wed Jul 11 09:52:18 2018
New Revision: 336822

URL: http://llvm.org/viewvc/llvm-project?rev=336822&view=rev
Log:
[InstSimplify] add/move tests for add folds; NFC

isKnownNegation() is currently proposed as part of D48754,
but it could be used to make InstSimplify stronger independently
of any abs() improvements.

Added:
    llvm/trunk/test/Transforms/InstSimplify/add.ll
Modified:
    llvm/trunk/test/Transforms/InstCombine/sub.ll

Modified: llvm/trunk/test/Transforms/InstCombine/sub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sub.ll?rev=336822&r1=336821&r2=336822&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sub.ll Wed Jul 11 09:52:18 2018
@@ -250,15 +250,6 @@ define i64 @test18(i64 %Y) {
   ret i64 %tmp.8
 }
 
-define i32 @test19(i32 %X, i32 %Y) {
-; CHECK-LABEL: @test19(
-; CHECK-NEXT:    ret i32 [[X:%.*]]
-;
-  %Z = sub i32 %X, %Y
-  %Q = add i32 %Z, %Y
-  ret i32 %Q
-}
-
 define i1 @test20(i32 %g, i32 %h) {
 ; CHECK-LABEL: @test20(
 ; CHECK-NEXT:    [[TMP_4:%.*]] = icmp ne i32 [[H:%.*]], 0

Added: llvm/trunk/test/Transforms/InstSimplify/add.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/add.ll?rev=336822&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/add.ll (added)
+++ llvm/trunk/test/Transforms/InstSimplify/add.ll Wed Jul 11 09:52:18 2018
@@ -0,0 +1,57 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i32 @common_sub_operand(i32 %X, i32 %Y) {
+; CHECK-LABEL: @common_sub_operand(
+; CHECK-NEXT:    ret i32 [[X:%.*]]
+;
+  %Z = sub i32 %X, %Y
+  %Q = add i32 %Z, %Y
+  ret i32 %Q
+}
+
+define i32 @negated_operand(i32 %x) {
+; CHECK-LABEL: @negated_operand(
+; CHECK-NEXT:    ret i32 0
+;
+  %negx = sub i32 0, %x
+  %r = add i32 %negx, %x
+  ret i32 %r
+}
+
+define <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) {
+; CHECK-LABEL: @negated_operand_commute_vec(
+; CHECK-NEXT:    ret <2 x i32> zeroinitializer
+;
+  %negx = sub <2 x i32> zeroinitializer, %x
+  %r = add <2 x i32> %x, %negx
+  ret <2 x i32> %r
+}
+
+define i8 @knownnegation(i8 %x, i8 %y) {
+; CHECK-LABEL: @knownnegation(
+; CHECK-NEXT:    [[XY:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[YX:%.*]] = sub i8 [[Y]], [[X]]
+; CHECK-NEXT:    [[R:%.*]] = add i8 [[XY]], [[YX]]
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %xy = sub i8 %x, %y
+  %yx = sub i8 %y, %x
+  %r = add i8 %xy, %yx
+  ret i8 %r
+}
+
+define <2 x i8> @knownnegation_commute_vec(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: @knownnegation_commute_vec(
+; CHECK-NEXT:    [[XY:%.*]] = sub <2 x i8> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[YX:%.*]] = sub <2 x i8> [[Y]], [[X]]
+; CHECK-NEXT:    [[R:%.*]] = add <2 x i8> [[YX]], [[XY]]
+; CHECK-NEXT:    ret <2 x i8> [[R]]
+;
+  %xy = sub <2 x i8> %x, %y
+  %yx = sub <2 x i8> %y, %x
+  %r = add <2 x i8> %yx, %xy
+  ret <2 x i8> %r
+}
+
+




More information about the llvm-commits mailing list