From bdad7992bc092f10124731eb3b3fbdf81e477b32 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 30 Aug 2023 09:45:06 -0400 Subject: [PATCH] agx: Add unit test for if_cmp fusing Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/test/test-optimizer.cpp | 32 ++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/asahi/compiler/test/test-optimizer.cpp b/src/asahi/compiler/test/test-optimizer.cpp index 9e05c5e..f02d854 100644 --- a/src/asahi/compiler/test/test-optimizer.cpp +++ b/src/asahi/compiler/test/test-optimizer.cpp @@ -14,24 +14,29 @@ agx_optimize_and_dce(agx_context *ctx) agx_dce(ctx, true); } -#define CASE(instr, expected, size) \ +#define CASE(instr, expected, size, returns) \ INSTRUCTION_CASE( \ { \ UNUSED agx_index out = agx_temp(b->shader, AGX_SIZE_##size); \ instr; \ - agx_unit_test(b, out); \ + if (returns) \ + agx_unit_test(b, out); \ }, \ { \ UNUSED agx_index out = agx_temp(b->shader, AGX_SIZE_##size); \ expected; \ - agx_unit_test(b, out); \ + if (returns) \ + agx_unit_test(b, out); \ }, \ agx_optimize_and_dce) -#define NEGCASE(instr, size) CASE(instr, instr, size) +#define NEGCASE(instr, size) CASE(instr, instr, size, true) -#define CASE16(instr, expected) CASE(instr, expected, 16) -#define CASE32(instr, expected) CASE(instr, expected, 32) +#define CASE16(instr, expected) CASE(instr, expected, 16, true) +#define CASE32(instr, expected) CASE(instr, expected, 32, true) + +#define CASE_NO_RETURN(instr, expected) \ + CASE(instr, expected, 32 /* irrelevant */, false) #define NEGCASE16(instr) NEGCASE(instr, 16) #define NEGCASE32(instr) NEGCASE(instr, 32) @@ -194,3 +199,18 @@ TEST_F(Optimizer, NoConversionsOn16BitALU) NEGCASE32(agx_fmov_to(b, out, agx_fadd(b, hx, hy))); } + +TEST_F(Optimizer, IfCondition) +{ + CASE_NO_RETURN(agx_if_icmp(b, agx_icmp(b, wx, wy, AGX_ICOND_UEQ, true), + agx_zero(), 1, AGX_ICOND_UEQ, true), + agx_if_icmp(b, wx, wy, 1, AGX_ICOND_UEQ, true)); + + CASE_NO_RETURN(agx_if_icmp(b, agx_fcmp(b, wx, wy, AGX_FCOND_EQ, true), + agx_zero(), 1, AGX_ICOND_UEQ, true), + agx_if_fcmp(b, wx, wy, 1, AGX_FCOND_EQ, true)); + + CASE_NO_RETURN(agx_if_icmp(b, agx_fcmp(b, hx, hy, AGX_FCOND_LT, false), + agx_zero(), 1, AGX_ICOND_UEQ, true), + agx_if_fcmp(b, hx, hy, 1, AGX_FCOND_LT, false)); +} -- 2.7.4