From beb5396d52d83dc9ccec8a427e12122cb33baf9d Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 1 Nov 2021 10:46:54 -0400 Subject: [PATCH] [InstCombine] add tests for bitwise logic folds; NFC --- llvm/test/Transforms/InstCombine/and-or.ll | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/and-or.ll b/llvm/test/Transforms/InstCombine/and-or.ll index 1e13be0..9f5c7ab 100644 --- a/llvm/test/Transforms/InstCombine/and-or.ll +++ b/llvm/test/Transforms/InstCombine/and-or.ll @@ -206,6 +206,57 @@ define i8 @or_and_or_commute3(i8 %x, i8 %y) { ret i8 %r } +define i8 @or_and2_or2(i8 %x) { +; CHECK-LABEL: @or_and2_or2( +; CHECK-NEXT: [[O1:%.*]] = or i8 [[X:%.*]], 1 +; CHECK-NEXT: call void @use(i8 [[O1]]) +; CHECK-NEXT: [[O2:%.*]] = or i8 [[X]], 2 +; CHECK-NEXT: call void @use(i8 [[O2]]) +; CHECK-NEXT: [[X1:%.*]] = and i8 [[O1]], -71 +; CHECK-NEXT: call void @use(i8 [[X1]]) +; CHECK-NEXT: [[X2:%.*]] = and i8 [[O2]], 66 +; CHECK-NEXT: call void @use(i8 [[X2]]) +; CHECK-NEXT: [[BITFIELD:%.*]] = and i8 [[X]], -8 +; CHECK-NEXT: [[R:%.*]] = or i8 [[BITFIELD]], 3 +; CHECK-NEXT: ret i8 [[R]] +; + %o1 = or i8 %x, 1 + call void @use(i8 %o1) + %o2 = or i8 %x, 2 + call void @use(i8 %o2) + %x1 = and i8 %o1, 185 + call void @use(i8 %x1) + %x2 = and i8 %o2, 66 + call void @use(i8 %x2) + %r = or i8 %x1, %x2 + ret i8 %r +} + +define <2 x i8> @or_and2_or2_splat(<2 x i8> %x) { +; CHECK-LABEL: @or_and2_or2_splat( +; CHECK-NEXT: [[O1:%.*]] = or <2 x i8> [[X:%.*]], +; CHECK-NEXT: call void @use_vec(<2 x i8> [[O1]]) +; CHECK-NEXT: [[O2:%.*]] = or <2 x i8> [[X]], +; CHECK-NEXT: call void @use_vec(<2 x i8> [[O2]]) +; CHECK-NEXT: [[X1:%.*]] = and <2 x i8> [[O1]], +; CHECK-NEXT: call void @use_vec(<2 x i8> [[X1]]) +; CHECK-NEXT: [[X2:%.*]] = and <2 x i8> [[O2]], +; CHECK-NEXT: call void @use_vec(<2 x i8> [[X2]]) +; CHECK-NEXT: [[R:%.*]] = or <2 x i8> [[X1]], [[X2]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %o1 = or <2 x i8> %x, + call void @use_vec(<2 x i8> %o1) + %o2 = or <2 x i8> %x, + call void @use_vec(<2 x i8> %o2) + %x1 = and <2 x i8> %o1, + call void @use_vec(<2 x i8> %x1) + %x2 = and <2 x i8> %o2, + call void @use_vec(<2 x i8> %x2) + %r = or <2 x i8> %x1, %x2 + ret <2 x i8> %r +} + ; Check variants of: ; and ({x}or X, Y), C --> {x}or X, (and Y, C) ; ...in the following 5 tests. -- 2.7.4