[Matrix] Emit assumption that matrix indices are valid.
authorFlorian Hahn <flo@fhahn.com>
Wed, 22 Sep 2021 09:28:36 +0000 (10:28 +0100)
committerFlorian Hahn <flo@fhahn.com>
Wed, 22 Sep 2021 11:27:37 +0000 (12:27 +0100)
commitea21d688dc0a420b9fc385562a46017fb39b13e5
treeb6344718c7ef6dbc5543743b7bc8c42f2febd641
parent9f34f75ff8f49b0efca6e20d916527a2c432d8b4
[Matrix] Emit assumption that matrix indices are valid.

The matrix extension requires the indices for matrix subscript
expression to be valid and it is UB otherwise.

extract/insertelement produce poison if the index is invalid, which
limits the optimizer to not be bale to scalarize load/extract pairs for
example, which causes very suboptimal code to be generated when using
matrix subscript expressions with variable indices for large matrixes.

This patch updates IRGen to emit assumes to for index expression to
convey the information that the index must be valid.

This also adjusts the order in which operations are emitted slightly, so
indices & assumes are added before the load of the matrix value.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D102478
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGen/matrix-type-operators.c
clang/test/CodeGenCXX/matrix-type-operators.cpp
clang/test/CodeGenObjC/matrix-type-operators.m
llvm/include/llvm/IR/MatrixBuilder.h