From 33a194b158069fdd713665f9cccf5dac0bc8a781 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Thu, 5 Oct 2023 20:01:55 +0800 Subject: [PATCH] [InstCombine] Add pre-commit tests for #67915. NFC. --- llvm/test/Transforms/InstCombine/and.ll | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/and.ll b/llvm/test/Transforms/InstCombine/and.ll index 90f027010e2aea..528a4e62c192d0 100644 --- a/llvm/test/Transforms/InstCombine/and.ll +++ b/llvm/test/Transforms/InstCombine/and.ll @@ -2546,3 +2546,39 @@ define i32 @and_zext_eq_zero(i32 %A, i32 %C) { %5 = and i32 %2, %4 ret i32 %5 } + +define i32 @canonicalize_and_add_power2_or_zero(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_add_power2_or_zero( +; CHECK-NEXT: [[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT: [[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT: call void @use32(i32 [[P2]]) +; CHECK-NEXT: [[VAL:%.*]] = add i32 [[P2]], [[X:%.*]] +; CHECK-NEXT: [[AND:%.*]] = and i32 [[VAL]], [[P2]] +; CHECK-NEXT: ret i32 [[AND]] +; + %ny = sub i32 0, %y + %p2 = and i32 %y, %ny + call void @use32(i32 %p2) ; keep p2 + + %val = add i32 %x, %p2 + %and = and i32 %val, %p2 + ret i32 %and +} + +define i32 @canonicalize_and_sub_power2_or_zero(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_sub_power2_or_zero( +; CHECK-NEXT: [[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT: [[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT: call void @use32(i32 [[P2]]) +; CHECK-NEXT: [[VAL:%.*]] = sub i32 [[X:%.*]], [[P2]] +; CHECK-NEXT: [[AND:%.*]] = and i32 [[VAL]], [[P2]] +; CHECK-NEXT: ret i32 [[AND]] +; + %ny = sub i32 0, %y + %p2 = and i32 %y, %ny + call void @use32(i32 %p2) ; keep p2 + + %val = sub i32 %x, %p2 + %and = and i32 %val, %p2 + ret i32 %and +}