From: Sanjay Patel Date: Wed, 24 May 2017 14:21:31 +0000 (+0000) Subject: [InstCombine] add tests to document bitcast + bitwise-logic behavior; NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=852ab094ff77c05ade3a20e414f092840b53bcb7;p=llvm [InstCombine] add tests to document bitcast + bitwise-logic behavior; NFC The solution for PR26702 ( https://bugs.llvm.org/show_bug.cgi?id=26702 ) added a canonicalization rule, but the minimal regression tests don't demonstrate how that rule interacts with other folds. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303750 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Transforms/InstCombine/bitcast.ll b/test/Transforms/InstCombine/bitcast.ll index 2e7f30fee14..4cf3f27ab01 100644 --- a/test/Transforms/InstCombine/bitcast.ll +++ b/test/Transforms/InstCombine/bitcast.ll @@ -70,6 +70,51 @@ define <2 x i32> @or_bitcast_int_to_vec(i64 %a) { ret <2 x i32> %t2 } +; PR26702 - https://bugs.llvm.org//show_bug.cgi?id=26702 +; Bitcast is canonicalized below logic, so we can see the not-not pattern. + +define <2 x i64> @is_negative(<4 x i32> %x) { +; CHECK-LABEL: @is_negative( +; CHECK-NEXT: [[LOBIT:%.*]] = ashr <4 x i32> %x, +; CHECK-NEXT: [[NOTNOT:%.*]] = bitcast <4 x i32> [[LOBIT]] to <2 x i64> +; CHECK-NEXT: ret <2 x i64> [[NOTNOT]] +; + %lobit = ashr <4 x i32> %x, + %not = xor <4 x i32> %lobit, + %bc = bitcast <4 x i32> %not to <2 x i64> + %notnot = xor <2 x i64> %bc, + ret <2 x i64> %notnot +} + +; This variation has an extra bitcast at the end. This means that the 2nd xor +; can be done in <4 x i32> to eliminate a bitcast regardless of canonicalizaion. + +define <4 x i32> @is_negative_bonus_bitcast(<4 x i32> %x) { +; CHECK-LABEL: @is_negative_bonus_bitcast( +; CHECK-NEXT: [[LOBIT:%.*]] = ashr <4 x i32> %x, +; CHECK-NEXT: ret <4 x i32> [[LOBIT]] +; + %lobit = ashr <4 x i32> %x, + %not = xor <4 x i32> %lobit, + %bc = bitcast <4 x i32> %not to <2 x i64> + %notnot = xor <2 x i64> %bc, + %bc2 = bitcast <2 x i64> %notnot to <4 x i32> + ret <4 x i32> %bc2 +} + +; Negative test: bitcasts are canonicalized below bitwise logic. No changes here. + +define <2 x i8> @canonicalize_bitcast_logic_with_constant(<4 x i4> %x) { +; CHECK-LABEL: @canonicalize_bitcast_logic_with_constant( +; CHECK-NEXT: [[A:%.*]] = and <4 x i4> %x, +; CHECK-NEXT: [[B:%.*]] = bitcast <4 x i4> [[A]] to <2 x i8> +; CHECK-NEXT: ret <2 x i8> [[B]] +; + %a = and <4 x i4> %x, + %b = bitcast <4 x i4> %a to <2 x i8> + ret <2 x i8> %b +} + ; PR27925 - https://llvm.org/bugs/show_bug.cgi?id=27925 define <4 x i32> @bitcasts_and_bitcast(<4 x i32> %a, <8 x i16> %b) {