[llvm] bfb915e - [InstCombine] add tests for 'sub nuw' with zext; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 19 12:12:30 PDT 2022


Author: Sanjay Patel
Date: 2022-06-19T15:12:19-04:00
New Revision: bfb915ec8bd057c566772b6f620a5ad3f55e9e17

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

LOG: [InstCombine] add tests for 'sub nuw' with zext; 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 3480a6a3313c..039441f9188a 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -1923,3 +1923,80 @@ define i16 @srem_sext_noundef(i8 noundef %x, i8 %y) {
   %z = sub i16 %sx, %sd
   ret i16 %z
 }
+
+define i16 @zext_nuw_noundef(i8 noundef %x, i8 %y) {
+; CHECK-LABEL: @zext_nuw_noundef(
+; CHECK-NEXT:    [[D:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[EX:%.*]] = zext i8 [[X]] to i16
+; CHECK-NEXT:    [[ED:%.*]] = zext i8 [[D]] to i16
+; CHECK-NEXT:    [[Z:%.*]] = sub nsw i16 [[EX]], [[ED]]
+; CHECK-NEXT:    ret i16 [[Z]]
+;
+  %d = sub nuw i8 %x, %y
+  %ex = zext i8 %x to i16
+  %ed = zext i8 %d to i16
+  %z = sub i16 %ex, %ed
+  ret i16 %z
+}
+
+define i16 @zext_nuw(i8 %x, i8 %y) {
+; CHECK-LABEL: @zext_nuw(
+; CHECK-NEXT:    [[D:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[EX:%.*]] = zext i8 [[X]] to i16
+; CHECK-NEXT:    [[ED:%.*]] = zext i8 [[D]] to i16
+; CHECK-NEXT:    [[Z:%.*]] = sub nsw i16 [[EX]], [[ED]]
+; CHECK-NEXT:    ret i16 [[Z]]
+;
+  %d = sub nuw i8 %x, %y
+  %ex = zext i8 %x to i16
+  %ed = zext i8 %d to i16
+  %z = sub i16 %ex, %ed
+  ret i16 %z
+}
+
+define i16 @zext_noundef(i8 noundef %x, i8 %y) {
+; CHECK-LABEL: @zext_noundef(
+; CHECK-NEXT:    [[D:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[EX:%.*]] = zext i8 [[X]] to i16
+; CHECK-NEXT:    [[ED:%.*]] = zext i8 [[D]] to i16
+; CHECK-NEXT:    [[Z:%.*]] = sub nsw i16 [[EX]], [[ED]]
+; CHECK-NEXT:    ret i16 [[Z]]
+;
+  %d = sub i8 %x, %y
+  %ex = zext i8 %x to i16
+  %ed = zext i8 %d to i16
+  %z = sub i16 %ex, %ed
+  ret i16 %z
+}
+
+define i16 @zext_nsw_noundef_wrong_val(i8 noundef %x, i8 noundef %y, i8 noundef %q) {
+; CHECK-LABEL: @zext_nsw_noundef_wrong_val(
+; CHECK-NEXT:    [[D:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[EQ:%.*]] = zext i8 [[Q:%.*]] to i16
+; CHECK-NEXT:    [[ED:%.*]] = zext i8 [[D]] to i16
+; CHECK-NEXT:    [[Z:%.*]] = sub nsw i16 [[EQ]], [[ED]]
+; CHECK-NEXT:    ret i16 [[Z]]
+;
+  %d = sub nuw i8 %x, %y
+  %eq = zext i8 %q to i16
+  %ed = zext i8 %d to i16
+  %z = sub i16 %eq, %ed
+  ret i16 %z
+}
+
+define i16 @srem_zext_noundef(i8 noundef %x, i8 %y) {
+; CHECK-LABEL: @srem_zext_noundef(
+; CHECK-NEXT:    [[R:%.*]] = urem i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[D:%.*]] = sub nuw i8 [[X]], [[R]]
+; CHECK-NEXT:    [[ED:%.*]] = zext i8 [[D]] to i16
+; CHECK-NEXT:    [[EX:%.*]] = zext i8 [[X]] to i16
+; CHECK-NEXT:    [[Z:%.*]] = sub nsw i16 [[EX]], [[ED]]
+; CHECK-NEXT:    ret i16 [[Z]]
+;
+  %r = urem i8 %x, %y
+  %d = sub i8 %x, %r
+  %ed = zext i8 %d to i16
+  %ex = zext i8 %x to i16
+  %z = sub i16 %ex, %ed
+  ret i16 %z
+}


        


More information about the llvm-commits mailing list