Issue 241086
Summary [HLSL][Matrix] Element-wise `*`, `/`, and negation aren't supported on matrices
Labels new issue
Assignees kmpeng
Reporter kmpeng
    In HLSL, `*` and `/` between two matrices and negating a matrix should be element-wise, like they are for vectors. Clang doesn't support any of them element-wise. It treats `*` between two matrices as a matrix multiply, so it only compiles when the first matrix's column count matches the second's row count. `/` between two matrices and negating a matrix aren't supported at all.

Repro:
https://godbolt.org/z/adKeG9sG8
```hlsl
export float2x2 mul(float2x2 a, float2x2 b) { 
    return a * b; 
}
```
emits a matrix multiply instead of element-wise `fmul`s:
```llvm
%3 = call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.matrix.multiply.v4f32.v4f32.v4f32(<4 x float> %1, <4 x float> %2, i32 2, i32 2, i32 2)
```

https://godbolt.org/z/5vMoh9oG5
```hlsl
export float2x3 mul(float2x3 a, float2x3 b) { 
    return a * b; 
}
export float2x2 div(float2x2 a, float2x2 b) { 
    return a / b; 
}
export float2x2 neg(float2x2 a) { 
    return -a; 
}
```
```
<source>:2:14: error: invalid operands to binary _expression_ ('float2x3' (aka 'matrix<float, 2, 3>') and 'float2x3')
    2 |     return a * b; 
      |            ~ ^ ~
<source>:5:14: error: invalid operands to binary _expression_ ('float2x2' (aka 'matrix<float, 2, 2>') and 'float2x2')
    5 |     return a / b; 
 |            ~ ^ ~
<source>:8:12: error: invalid argument type 'float2x2' (aka 'matrix<float, 2, 2>') to unary _expression_
    8 |     return -a; 
 |            ^~
3 errors generated.
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to