From f8cf6d027b54e0c2a3804e272a6d3ace95952ef9 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 3 Nov 2020 14:06:42 +0300 Subject: [PATCH] [NFC][InstCombine] Negator: add test coverage for `(?? - (%y + C))` pattern (PR47997) --- .../InstCombine/sub-of-negatible.ll | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) 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) {