This might be useful because clang will add
barriers for pointer comparisons.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
I guess the patch is implemented correctly, but, can you please provide an example of clang emitting such construct?
Check out https://reviews.llvm.org/D32378
Clang will add barriers for some of pointer casts and pointer compares, so it is important to propagate null.
Propagating undef is only to make sure barriers don't limit optimizations like DCE etc.
lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
4432–4438 ↗ | (On Diff #96400) | This probably belongs in the constant folder. |
lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
4432–4438 ↗ | (On Diff #96400) | Do you mean folding barrier(const) -> const? |
lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
4432–4438 ↗ | (On Diff #96400) | Not for all constants, just undef and null in address space zero. |
lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
4432–4438 ↗ | (On Diff #96400) | I don't understand what you mean. Do you mean to move this code somewhere else? |
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
1779–1783 ↗ | (On Diff #96437) | Isn't this only valid if the address space is zero? |
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
1779–1783 ↗ | (On Diff #96437) | True, but can you pass pointer from another addrspace to invariant.group.barrier? When I try %X = addrspacecast i8* null to i8 addrspace(1)* %b2 = call i8* @llvm.invariant.group.barrier(i8* %X) I get error: '%X' defined with type 'i8 addrspace(1)*' I could add this line: cast<PointerType>(Operands[0]->getType())->getAddressSpace() == 0 but I won't be able to test it in any way if I am not wrong. |
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
1779–1783 ↗ | (On Diff #96437) | Not positive about this, but does it work if you do: %b2 = call i8* @llvm.invariant.group.barrier(i8* addrspace(4)* @global0) where @global0 = addrspace(4) constant i8* null |
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
1779–1783 ↗ | (On Diff #96437) | Thanks for help Davide, but it still doesn't work for me. I get the following error: error: '@llvm.invariant.group.barrier' defined with type 'i8* (i8*)*' %b = call i8* @llvm.invariant.group.barrier(i8* addrspace(4)* @global0) ^ the code looks like this @global0 = addrspace(4) constant i8* null define i8* @differentAddrspace() { %b = call i8* @llvm.invariant.group.barrier(i8* addrspace(4)* @global0) ret i8* %b } declare i8* @llvm.invariant.group.barrier(i8*) |
llvm/test/Transforms/InstCombine/invariant.group.ll | ||
---|---|---|
4 ↗ | (On Diff #145366) | nit: simplify (in other places too) |