From 952e7106b34097ba447326a58e51778af25f070f Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Wed, 20 May 2020 20:54:06 +0300 Subject: [PATCH] [NFC][InstCombine] Negator: tests for extractelement negation --- .../Transforms/InstCombine/sub-of-negatible.ll | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll index 0f2e633..9526946 100644 --- a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll +++ b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll @@ -1,6 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt %s -instcombine -S | FileCheck %s +declare void @use4(i4) declare void @use8(i8) declare void @use_v2i4(<2 x i4>) @@ -914,3 +915,35 @@ define i8 @add_via_or_with_no_common_bits_set_extrause(i8 %x, i8 %y) { %t3 = sub i8 %x, %t2 ret i8 %t3 } + +; `extractelement` is negatible if source operand is negatible. +define i4 @negate_extractelement(<2 x i4> %x, i32 %y, i4 %z) { +; CHECK-LABEL: @negate_extractelement( +; CHECK-NEXT: [[T0:%.*]] = sub <2 x i4> zeroinitializer, [[X:%.*]] +; CHECK-NEXT: call void @use_v2i4(<2 x i4> [[T0]]) +; CHECK-NEXT: [[T1:%.*]] = extractelement <2 x i4> [[T0]], i32 [[Y:%.*]] +; CHECK-NEXT: [[T2:%.*]] = sub i4 [[Z:%.*]], [[T1]] +; CHECK-NEXT: ret i4 [[T2]] +; + %t0 = sub <2 x i4> zeroinitializer, %x + call void @use_v2i4(<2 x i4> %t0) + %t1 = extractelement <2 x i4> %t0, i32 %y + %t2 = sub i4 %z, %t1 + ret i4 %t2 +} +define i4 @negate_extractelement_extrause(<2 x i4> %x, i32 %y, i4 %z) { +; CHECK-LABEL: @negate_extractelement_extrause( +; CHECK-NEXT: [[T0:%.*]] = sub <2 x i4> zeroinitializer, [[X:%.*]] +; CHECK-NEXT: call void @use_v2i4(<2 x i4> [[T0]]) +; CHECK-NEXT: [[T1:%.*]] = extractelement <2 x i4> [[T0]], i32 [[Y:%.*]] +; CHECK-NEXT: call void @use4(i4 [[T1]]) +; CHECK-NEXT: [[T2:%.*]] = sub i4 [[Z:%.*]], [[T1]] +; CHECK-NEXT: ret i4 [[T2]] +; + %t0 = sub <2 x i4> zeroinitializer, %x + call void @use_v2i4(<2 x i4> %t0) + %t1 = extractelement <2 x i4> %t0, i32 %y + call void @use4(i4 %t1) + %t2 = sub i4 %z, %t1 + ret i4 %t2 +} -- 2.7.4