OpenCL constant address space is immutable, therefore pointers to constant address space can
be marked with llvm.invariant.start permanently.
This should allow more optimization opportunities in LLVM passes.
Paths
| Differential D75423
[OpenCL] Mark pointers to constant address space as invariant Needs ReviewPublic Authored by yaxunl on Mar 1 2020, 7:05 AM.
Details
Diff Detail Event Timeline
Comment Actions invariant checking already takes account of loading from constant address space or memory (AA::pointsToConstantMemory), that's almost equivalent to adding invariant attributes. Why do we mark these constant loads with additional attributes? Comment Actions
I got this request from Matt. He wants a consistent representation for invariant load, not relying on alias analysis. Comment Actions
If alias analysis already knows that all memory in the constant address space is immutable, I agree that should be sufficient, at least on targets where the constant address space is actually a different address space in LLVM IR. If it only knows that when it can resolve an access down to a specific constant global variable, this patch is still providing value because it applies even for accesses through a pointer. Comment Actions
There is plan for amdgcn target to drop constant address space in IR and use global address space instead. Also, currently there are targets (e.g. x86_64) supporting OpenCL which does not have constant address space in IR. Comment Actions
Okay, then I have no problem taking a patch for this into IRGen. But I think it should be fine to do this by adding the invariant-load metadata when loading from an l-value instead of injecting invariant-groups into l-value emission. Comment Actions
The pointer to constant may be casted to a generic pointer then loaded. If we only mark load from pointer to constant, we loses information. Comment Actions
A lot of those conversions don't go through EmitLValue. Doing this at this level in EmitLValue both complicates the code and will introduce a lot of redundant intrinsic calls. If you need to do it, you should do it at the root where a pointer is being turned into an LValue.
Revision Contents
Diff 247688 clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/CodeGenOpenCL/invariant.cl
clang/test/CodeGenOpenCL/printf.cl
|
This check is already done by CreateBitCast.