This adds an rsqrt op to the standard dialect, and lowers
it as 1 / sqrt to the LLVM dialect.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Mostly good, let's make sure it works for other types than f32.
mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp | ||
---|---|---|
1686 | This may not necessarily work if the operand type is not float. Maybe you could dispatch to different attributes based on type? | |
mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir | ||
23 | Could we also have a test for f64/double? |
mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp | ||
---|---|---|
1686 | I tried to fix this by using getFloatAttr(operandType, 1.0) instead. Not sure whether operandType is the actual type it expects here though. Now I get llvm.float / llvm.double as types for the constants, before it was f32. |
PTAL. The tests seem to work now.
mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir | ||
---|---|---|
48 | Does this look ok? I am not sure whether the operand type of constant is allowed to be different from the result type. But seems there is no assert that is triggered, so maybe it supports broadcasts? |
mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir | ||
---|---|---|
48 | I think you need something like llvm.mlir.constant(dense<1.0> : vector<4xf32>) : !llvm<"<4 x float>">. We have SplatElementsAttr to broadcast constants in a vector, which is printed like that. |
Sorry for not following up sooner, I was busy with other stuff yesterday. Today, with some help by Stephan I was able to make this work. I copied the handling with unrolling multi-dimensional vectors from the generic elementwise op handling. This could potentially be refactored, especially I wonder whether Tanh should also use this.
I copied the handling with unrolling multi-dimensional vectors from the generic elementwise op handling. This could potentially be refactored, especially I wonder whether Tanh should also use this.
I think I've seen a commit that removed the default tanh lowering recently. Anyway, a refactoring is welcome if you think it makes sense, in a separate commit.
Landed as revision 91acb5b3e1c3
Unforunately I forgot to reset the link to this review, after I had accidentally created https://reviews.llvm.org/D75353
mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp | ||
---|---|---|
1674 | Don't use dyn_cast_or_null here, the result of getType is never null. Use dyn_cast if you know the input is non-null. |
mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp | ||
---|---|---|
1674 | Thanks for the suggestion :) |
Don't use dyn_cast_or_null here, the result of getType is never null. Use dyn_cast if you know the input is non-null.