[llvm] c4d8d91 - [InstCombine] Add tests for folding `(X + Y) - (W + Z)`; NFC

Noah Goldstein via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 15:59:46 PST 2023


Author: Noah Goldstein
Date: 2023-11-20T17:59:26-06:00
New Revision: c4d8d9167938aa09fd7b1492a4abcfcf5bc1a9ca

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

LOG: [InstCombine] Add tests for folding `(X + Y) - (W + Z)`; NFC

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/sub.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll
index 754b532de20083d..08748d263ba1f78 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -2580,3 +2580,49 @@ define i8 @
diff _of_muls2(i8 %x, i8 %y, i8 %z) {
   %r = sub i8 %x2, %m
   ret i8 %r
 }
+
+define i8 @sub_of_adds_2xz_multiuse(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @sub_of_adds_2xz_multiuse(
+; CHECK-NEXT:    [[XZ:%.*]] = add i8 [[X:%.*]], [[Z:%.*]]
+; CHECK-NEXT:    [[YZ:%.*]] = add i8 [[Z]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = sub i8 [[XZ]], [[YZ]]
+; CHECK-NEXT:    call void @use8(i8 [[XZ]])
+; CHECK-NEXT:    call void @use8(i8 [[YZ]])
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %xz = add i8 %x, %z
+  %yz = add i8 %z, %y
+  %r = sub i8 %xz, %yz
+  call void @use8(i8 %xz)
+  call void @use8(i8 %yz)
+  ret i8 %r
+}
+
+define i8 @sub_of_adds_2xc_multiuse2_fail(i8 %x, i8 %y) {
+; CHECK-LABEL: @sub_of_adds_2xc_multiuse2_fail(
+; CHECK-NEXT:    [[XC:%.*]] = add i8 [[X:%.*]], 10
+; CHECK-NEXT:    [[YC:%.*]] = add i8 [[Y:%.*]], 11
+; CHECK-NEXT:    [[R:%.*]] = sub i8 [[XC]], [[YC]]
+; CHECK-NEXT:    call void @use8(i8 [[XC]])
+; CHECK-NEXT:    call void @use8(i8 [[YC]])
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %xc = add i8 %x, 10
+  %yc = add i8 %y, 11
+  %r = sub i8 %xc, %yc
+  call void @use8(i8 %xc)
+  call void @use8(i8 %yc)
+  ret i8 %r
+}
+
+define i8 @sub_of_adds_2xc(i8 %x, i8 %y) {
+; CHECK-LABEL: @sub_of_adds_2xc(
+; CHECK-NEXT:    [[TMP1:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = add i8 [[TMP1]], 2
+; CHECK-NEXT:    ret i8 [[R]]
+;
+  %xc = add i8 %x, 10
+  %yc = add i8 %y, 8
+  %r = sub i8 %xc, %yc
+  ret i8 %r
+}


        


More information about the llvm-commits mailing list