Mesa (main): pan/bi: Test avoiding *FADD.v2f16 hazard in optimizer

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Feb 18 16:34:51 UTC 2022


Module: Mesa
Branch: main
Commit: 9d95561c93c48d15786a9559cdc927218a68f03b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9d95561c93c48d15786a9559cdc927218a68f03b

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Thu Feb 17 19:18:08 2022 -0500

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 <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15072>

---

 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 923386845b3..9b418880647 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),



More information about the mesa-commit mailing list