[PATCH] D133287: [InstCombine] Test for matrix multiplication negation optimisation.

Zain Jaffal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 5 03:01:11 PDT 2022


zjaffal created this revision.
zjaffal added reviewers: spatel, fhahn, lebedev.ri, RKSimon, anemet, thegameg.
Herald added a project: All.
zjaffal requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

If one of the operands is negated in a multiplication we can optimise the operation by moving the negation to the smallest operand or to the result


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133287

Files:
  llvm/test/Transforms/InstCombine/matrix-multiplication-negation.ll


Index: llvm/test/Transforms/InstCombine/matrix-multiplication-negation.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/matrix-multiplication-negation.ll
@@ -0,0 +1,50 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define <3 x double> @matrix_multiply_v9f64_v3f64(<9 x double> %a, <3 x double> %b) {
+; CHECK-LABEL: @matrix_multiply_v9f64_v3f64(
+; CHECK-NEXT:    [[A_NEG:%.*]] = fneg <9 x double> [[A:%.*]]
+; CHECK-NEXT:    [[RES:%.*]] = tail call <3 x double> @llvm.matrix.multiply.v3f64.v9f64.v3f64(<9 x double> [[A_NEG]], <3 x double> [[B:%.*]], i32 3, i32 3, i32 1)
+; CHECK-NEXT:    ret <3 x double> [[RES]]
+;
+  %a.neg = fneg <9 x double> %a
+  %res = tail call <3 x double> @llvm.matrix.multiply.v3f64.v9f64.v3f64(<9 x double> %a.neg, <3 x double> %b, i32 3, i32 3, i32 1)
+  ret <3 x double> %res
+}
+declare <3 x double> @llvm.matrix.multiply.v3f64.v9f64.v3f64(<9 x double>, <3 x double>, i32 immarg, i32 immarg, i32 immarg) #1
+
+define <9 x double> @matrix_multiply_v27f64_v3f64(<27 x double> %a, <3 x double> %b) {
+; CHECK-LABEL: @matrix_multiply_v27f64_v3f64(
+; CHECK-NEXT:    [[A_NEG:%.*]] = fneg <27 x double> [[A:%.*]]
+; CHECK-NEXT:    [[RES:%.*]] = tail call <9 x double> @llvm.matrix.multiply.v9f64.v27f64.v3f64(<27 x double> [[A_NEG]], <3 x double> [[B:%.*]], i32 9, i32 3, i32 1)
+; CHECK-NEXT:    ret <9 x double> [[RES]]
+;
+  %a.neg = fneg <27 x double> %a
+  %res = tail call <9 x double> @llvm.matrix.multiply.v9f64.v27f64.v3f64(<27 x double> %a.neg, <3 x double> %b, i32 9, i32 3, i32 1)
+  ret <9 x double> %res
+}
+declare <9 x double> @llvm.matrix.multiply.v9f64.v27f64.v3f64(<27 x double>, <3 x double>, i32 immarg, i32 immarg, i32 immarg) #1
+
+define <12 x double> @matrix_multiply_v15f64_v20f64(<15 x double> %a, <20 x double> %b) {
+; CHECK-LABEL: @matrix_multiply_v15f64_v20f64(
+; CHECK-NEXT:    [[A_NEG:%.*]] = fneg <15 x double> [[A:%.*]]
+; CHECK-NEXT:    [[RES:%.*]] = tail call <12 x double> @llvm.matrix.multiply.v12f64.v15f64.v20f64(<15 x double> [[A_NEG]], <20 x double> [[B:%.*]], i32 3, i32 5, i32 4)
+; CHECK-NEXT:    ret <12 x double> [[RES]]
+;
+  %a.neg = fneg <15 x double> %a
+  %res = tail call <12 x double> @llvm.matrix.multiply.v12f64.v15f64.v20f64(<15 x double> %a.neg, <20 x double> %b, i32 3, i32 5, i32 4)
+  ret <12 x double> %res
+}
+declare <12 x double> @llvm.matrix.multiply.v12f64.v15f64.v20f64(<15 x double>, <20 x double>, i32 immarg, i32 immarg, i32 immarg) #1
+
+define <15 x double> @matrix_multiply_v3f64_v5f64(<3 x double> %a, <5 x double> %b) {
+; CHECK-LABEL: @matrix_multiply_v3f64_v5f64(
+; CHECK-NEXT:    [[A_NEG:%.*]] = fneg <3 x double> [[A:%.*]]
+; CHECK-NEXT:    [[RES:%.*]] = tail call <15 x double> @llvm.matrix.multiply.v15f64.v3f64.v5f64(<3 x double> [[A_NEG]], <5 x double> [[B:%.*]], i32 3, i32 1, i32 5)
+; CHECK-NEXT:    ret <15 x double> [[RES]]
+;
+  %a.neg = fneg <3 x double> %a
+  %res = tail call <15 x double> @llvm.matrix.multiply.v15f64.v3f64.v5f64(<3 x double> %a.neg, <5 x double> %b, i32 3, i32 1, i32 5)
+  ret <15 x double> %res
+}
+declare <15 x double> @llvm.matrix.multiply.v15f64.v3f64.v5f64(<3 x double>, <5 x double>, i32 immarg, i32 immarg, i32 immarg) #1


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133287.457918.patch
Type: text/x-patch
Size: 3335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220905/e3fe97d2/attachment.bin>


More information about the llvm-commits mailing list