From 9d95561c93c48d15786a9559cdc927218a68f03b Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 17 Feb 2022 19:18:08 -0500 Subject: [PATCH] pan/bi: Test avoiding *FADD.v2f16 hazard in optimizer This hazard exists but is obscure enough to be missed on our existing test coverage (e.g the conformance tests). Add piles of unit tests for it. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/test/test-optimizer.cpp | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/panfrost/bifrost/test/test-optimizer.cpp b/src/panfrost/bifrost/test/test-optimizer.cpp index 9233868..9b41888 100644 --- a/src/panfrost/bifrost/test/test-optimizer.cpp +++ b/src/panfrost/bifrost/test/test-optimizer.cpp @@ -107,6 +107,78 @@ TEST_F(Optimizer, FusedFABSNEGForFP16) bi_fmin_v2f16_to(b, reg, negabsx, bi_neg(y))); } +TEST_F(Optimizer, FuseFADD_F32WithEqualSourcesAbsAbsAndClamp) +{ + CASE({ + bi_instr *I = bi_fadd_f32_to(b, reg, bi_fabsneg_f32(b, bi_abs(x)), bi_abs(x), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }, { + bi_instr *I = bi_fadd_f32_to(b, reg, bi_abs(x), bi_abs(x), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }); + + CASE({ + bi_instr *I = bi_fadd_f32_to(b, reg, bi_abs(x), bi_fabsneg_f32(b, bi_abs(x)), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }, { + bi_instr *I = bi_fadd_f32_to(b, reg, bi_abs(x), bi_abs(x), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }); + + CASE({ + bi_instr *I = bi_fclamp_f32_to(b, reg, bi_fadd_f32(b, bi_abs(x), bi_abs(x), BI_ROUND_NONE)); + I->clamp = BI_CLAMP_CLAMP_0_INF; + }, { + bi_instr *I = bi_fadd_f32_to(b, reg, bi_abs(x), bi_abs(x), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_INF; + }); +} + +TEST_F(Optimizer, FuseFADD_V2F16WithDifferentSourcesAbsAbsAndClamp) +{ + CASE({ + bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_fabsneg_v2f16(b, bi_abs(x)), bi_abs(y), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }, { + bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_abs(y), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }); + + CASE({ + bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_fabsneg_v2f16(b, bi_abs(y)), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }, { + bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_abs(y), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }); + + CASE({ + bi_instr *I = bi_fclamp_v2f16_to(b, reg, bi_fadd_v2f16(b, bi_abs(x), bi_abs(y), BI_ROUND_NONE)); + I->clamp = BI_CLAMP_CLAMP_0_INF; + }, { + bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_abs(y), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_INF; + }); +} + +TEST_F(Optimizer, AvoidFADD_V2F16WithEqualSourcesAbsAbsAndClamp) +{ + NEGCASE({ + bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_fabsneg_v2f16(b, bi_abs(x)), bi_abs(x), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }); + + NEGCASE({ + bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_fabsneg_v2f16(b, bi_abs(x)), BI_ROUND_NONE); + I->clamp = BI_CLAMP_CLAMP_0_1; + }); + + NEGCASE({ + bi_instr *I = bi_fclamp_v2f16_to(b, reg, bi_fadd_v2f16(b, bi_abs(x), bi_abs(x), BI_ROUND_NONE)); + I->clamp = BI_CLAMP_CLAMP_0_INF; + }); +} + TEST_F(Optimizer, SwizzlesComposedForFP16) { CASE(bi_fadd_v2f16_to(b, reg, bi_fabsneg_v2f16(b, bi_swz_16(negabsx, true, false)), y, BI_ROUND_RTP), -- 2.7.4