[llvm] 762629b - [InstCombine] Add additional tests for nsw propagation during negation (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 23 02:38:50 PDT 2023
Author: Nikita Popov
Date: 2023-08-23T11:38:41+02:00
New Revision: 762629b2c67a7dc3961b868528c3770a4fa8b068
URL: https://github.com/llvm/llvm-project/commit/762629b2c67a7dc3961b868528c3770a4fa8b068
DIFF: https://github.com/llvm/llvm-project/commit/762629b2c67a7dc3961b868528c3770a4fa8b068.diff
LOG: [InstCombine] Add additional tests for nsw propagation during negation (NFC)
Added:
Modified:
llvm/test/Transforms/InstCombine/mul.ll
llvm/test/Transforms/InstCombine/nsw.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/mul.ll b/llvm/test/Transforms/InstCombine/mul.ll
index de2b5115266360..7e41b073d738f6 100644
--- a/llvm/test/Transforms/InstCombine/mul.ll
+++ b/llvm/test/Transforms/InstCombine/mul.ll
@@ -1543,6 +1543,28 @@ define <2 x i32> @mulsub2_vec_nonuniform_undef(<2 x i32> %a0) {
ret <2 x i32> %mul
}
+define i8 @mulsub_nsw(i8 %a1, i8 %a2) {
+; CHECK-LABEL: @mulsub_nsw(
+; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2:%.*]], [[A1:%.*]]
+; CHECK-NEXT: [[MUL:%.*]] = shl i8 [[A_NEG]], 1
+; CHECK-NEXT: ret i8 [[MUL]]
+;
+ %a = sub nsw i8 %a1, %a2
+ %mul = mul nsw i8 %a, -2
+ ret i8 %mul
+}
+
+define <2 x i8> @mulsub_nsw_undef(<2 x i8> %a1, <2 x i8> %a2) {
+; CHECK-LABEL: @mulsub_nsw_undef(
+; CHECK-NEXT: [[A_NEG:%.*]] = sub <2 x i8> [[A2:%.*]], [[A1:%.*]]
+; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i8> [[A_NEG]], <i8 1, i8 0>
+; CHECK-NEXT: ret <2 x i8> [[MUL]]
+;
+ %a = sub nsw <2 x i8> %a1, %a2
+ %mul = mul nsw <2 x i8> %a, <i8 -2, i8 undef>
+ ret <2 x i8> %mul
+}
+
define i32 @muladd2(i32 %a0) {
; CHECK-LABEL: @muladd2(
; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[A0:%.*]], 2
diff --git a/llvm/test/Transforms/InstCombine/nsw.ll b/llvm/test/Transforms/InstCombine/nsw.ll
index ea66409b34267a..d9dfa8fb387683 100644
--- a/llvm/test/Transforms/InstCombine/nsw.ll
+++ b/llvm/test/Transforms/InstCombine/nsw.ll
@@ -253,6 +253,47 @@ define i32 @sub_sub1_nsw_nsw(i32 %a, i32 %b, i32 %c) {
ret i32 %s2
}
+define i8 @neg_nsw_freeze(i8 %a1, i8 %a2) {
+; CHECK-LABEL: @neg_nsw_freeze(
+; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2:%.*]], [[A1:%.*]]
+; CHECK-NEXT: [[FR_NEG:%.*]] = freeze i8 [[A_NEG]]
+; CHECK-NEXT: ret i8 [[FR_NEG]]
+;
+ %a = sub nsw i8 %a1, %a2
+ %fr = freeze i8 %a
+ %neg = sub nsw i8 0, %fr
+ ret i8 %neg
+}
+
+define i8 @neg_nsw_phi(i1 %c, i8 %a1, i8 %a2, i8 %b1, i8 %b2) {
+; CHECK-LABEL: @neg_nsw_phi(
+; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK: if:
+; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2:%.*]], [[A1:%.*]]
+; CHECK-NEXT: br label [[JOIN:%.*]]
+; CHECK: else:
+; CHECK-NEXT: [[B_NEG:%.*]] = sub i8 [[B2:%.*]], [[B1:%.*]]
+; CHECK-NEXT: br label [[JOIN]]
+; CHECK: join:
+; CHECK-NEXT: [[PHI_NEG:%.*]] = phi i8 [ [[A_NEG]], [[IF]] ], [ [[B_NEG]], [[ELSE]] ]
+; CHECK-NEXT: ret i8 [[PHI_NEG]]
+;
+ br i1 %c, label %if, label %else
+
+if:
+ %a = sub nsw i8 %a1, %a2
+ br label %join
+
+else:
+ %b = sub nsw i8 %b1, %b2
+ br label %join
+
+join:
+ %phi = phi i8 [ %a, %if ], [ %b, %else ]
+ %neg = sub nsw i8 0, %phi
+ ret i8 %neg
+}
+
define i8 @neg_nsw_select(i1 %c, i8 %a1, i8 %a2, i8 %b1, i8 %b2) {
; CHECK-LABEL: @neg_nsw_select(
; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2:%.*]], [[A1:%.*]]
More information about the llvm-commits
mailing list