From bfb915ec8bd057c566772b6f620a5ad3f55e9e17 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sun, 19 Jun 2022 14:10:03 -0400 Subject: [PATCH] [InstCombine] add tests for 'sub nuw' with zext; NFC --- llvm/test/Transforms/InstCombine/sub.ll | 77 +++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll index 3480a6a..039441f 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 +} -- 2.7.4