[llvm] f8cf6d0 - [NFC][InstCombine] Negator: add test coverage for `(?? - (%y + C))` pattern (PR47997)
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 3 05:07:19 PST 2020
Author: Roman Lebedev
Date: 2020-11-03T16:06:51+03:00
New Revision: f8cf6d027b54e0c2a3804e272a6d3ace95952ef9
URL: https://github.com/llvm/llvm-project/commit/f8cf6d027b54e0c2a3804e272a6d3ace95952ef9
DIFF: https://github.com/llvm/llvm-project/commit/f8cf6d027b54e0c2a3804e272a6d3ace95952ef9.diff
LOG: [NFC][InstCombine] Negator: add test coverage for `(?? - (%y + C))` pattern (PR47997)
Added:
Modified:
llvm/test/Transforms/InstCombine/sub-of-negatible.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
index 6a809e17dcb2..40f51d2c75a2 100644
--- a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
+++ b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
@@ -309,6 +309,76 @@ define i8 @n14(i8 %x, i8 %y, i8 %z) {
ret i8 %t3
}
+define i8 @neg_of_add_with_constant(i8 %x) {
+; CHECK-LABEL: @neg_of_add_with_constant(
+; CHECK-NEXT: [[S_NEG:%.*]] = sub i8 -42, [[X:%.*]]
+; CHECK-NEXT: ret i8 [[S_NEG]]
+;
+ %s = add i8 %x, 42
+ %r = sub i8 0, %s
+ ret i8 %r
+}
+
+define i8 @neg_of_add_with_constant_multi_use(i8 %x) {
+; CHECK-LABEL: @neg_of_add_with_constant_multi_use(
+; CHECK-NEXT: [[S:%.*]] = add i8 [[X:%.*]], 42
+; CHECK-NEXT: call void @use8(i8 [[S]])
+; CHECK-NEXT: [[R:%.*]] = sub i8 0, [[S]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %s = add i8 %x, 42
+ call void @use8(i8 %s)
+ %r = sub i8 0, %s
+ ret i8 %r
+}
+
+define i8 @sub_from_constant_of_add_with_constant(i8 %x) {
+; CHECK-LABEL: @sub_from_constant_of_add_with_constant(
+; CHECK-NEXT: [[R:%.*]] = sub i8 -31, [[X:%.*]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %s = add i8 %x, 42
+ %r = sub i8 11, %s
+ ret i8 %r
+}
+
+define i8 @sub_from_constant_of_add_with_constant_multi_use(i8 %x) {
+; CHECK-LABEL: @sub_from_constant_of_add_with_constant_multi_use(
+; CHECK-NEXT: [[S:%.*]] = add i8 [[X:%.*]], 42
+; CHECK-NEXT: call void @use8(i8 [[S]])
+; CHECK-NEXT: [[R:%.*]] = sub i8 -31, [[X]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %s = add i8 %x, 42
+ call void @use8(i8 %s)
+ %r = sub i8 11, %s
+ ret i8 %r
+}
+
+define i8 @sub_from_variable_of_add_with_constant(i8 %x, i8 %y) {
+; CHECK-LABEL: @sub_from_variable_of_add_with_constant(
+; CHECK-NEXT: [[S:%.*]] = add i8 [[X:%.*]], 42
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[Y:%.*]], [[S]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %s = add i8 %x, 42
+ %r = sub i8 %y, %s
+ ret i8 %r
+}
+
+define i8 @sub_from_variable_of_add_with_constant_multi_use(i8 %x, i8 %y) {
+; CHECK-LABEL: @sub_from_variable_of_add_with_constant_multi_use(
+; CHECK-NEXT: [[S:%.*]] = add i8 [[X:%.*]], 42
+; CHECK-NEXT: call void @use8(i8 [[S]])
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[Y:%.*]], [[S]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %s = add i8 %x, 42
+ call void @use8(i8 %s)
+ %r = sub i8 %y, %s
+ ret i8 %r
+}
+
; Multiplication can be negated if either one of operands can be negated
; x - (y * z) -> x + ((-y) * z) or x + ((-z) * y)
define i8 @t15(i8 %x, i8 %y, i8 %z) {
More information about the llvm-commits
mailing list