-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regularize LLVM code to remove use of non standard integer types in fptoui and fptosi intrinsics #2500
Conversation
…ptoui and fptosi intrinsics Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
Please review once marked ready. Thanks |
Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
This PR tries to address a very limited set of issues found due to use of non-standard integer types. A more rounded solution may be required in the long run. Tracked here: #481 Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc | ||
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM | ||
|
||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data layout doesn't match the input LLVM IR ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix in upcoming patch. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the original testcase. Data layout is exactly the same as it is here. Can you please let me know how it does not match the input LLVM IR? Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n8:16:32:64
There is no "2" and "4" which would stand for i2 and i4. Which means, that the test case is either written artificially or generated using some hacks. If the later wouldn't it makes sense to investigate frontend hacks instead of changing translation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or if not hacks, may be just aggressive inst combine should respect data layout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned earlier, the test case is a 'modified' version of an actual LLVM IR file created using upstream LLVM compiler (LLVM.org). I have not changed the datalayout or the instructions related to 'i2' uses.
I am trying to figure out if this might be the case of the optimization not handling data layout correctly.
I am however surprised that 'llvm-as' does not complain about this LLVM IR. And I am also sure the verifier code runs at some time during front-end compilation. However, it is quite possible that they do not try to 'verify' datalayout related issues.
I went a bit deeper. i see that there is a helper function 'isLegalInteger' in the datalayout. However, this particular optimization does not call this function to check for legality. I will try to get this answered in the community.
In the meanwhile, would it make sense to 'merge' this as is and then revert it if/when frontend fix is in place?
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the entries in datalayout are expected to be more of a guide that strict rules. for example, It is not documented anywhere that i2 is illegal if it is not listed in the target datalayout, thought it does sound counter-intuitive. I think we might have to assume that this LLVM IR is legal and proceed with the change here.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the entries in datalayout are expected to be more of a guide that strict rules. for example, It is not documented anywhere that i2 is illegal if it is not listed in the target datalayout, thought it does sound counter-intuitive. I think we might have to assume that this LLVM IR is legal and proceed with the change here.
Thanks
I agree. The fact the datalayout
field does not explicitly "mention" i2
doesn't prevent the LLVM optimizer to use i2 as an intermediat type during optimization IMO. The LLVM language spec simply states that the " data layout string that specifies how data is to be laid out in memory". There isn't anything that says using i2 is illegal.
Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
Signed-off-by: Sudarsanam, Arvind <arvind.sudarsanam@intel.com>
Are there any more open issues/concerns? I have verified with LLVM documentation that generation of data types not mentioned in the datalayout is not explicitly called out as illegal. Please let me know if there is any evidence contrary to this. Thanks a lot for your insightful feedbacks on this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more concerns from my side.
Thanks everyone for the reviews. |
It is possible that incoming LLVM IR conversion instructions convert floating point to non-standard integer types.
For e.g. %0 = call i2 @llvm.fptosi.sat.i2.f32(float %input)
Such types are not supported in SPIR-V. This PR cleans up such code and removes occurrence of non-standard integer types.
Thanks