Follow-up to D68244 to account for a corner case discussed in:
https://bugs.llvm.org/show_bug.cgi?id=43501
Add one more restriction: if the pointer is deref-or-null and in a non-default (non-zero) address space, we can't assume inbounds.
Differential D68706
[InstCombine] don't assume 'inbounds' for bitcast deref or null pointer in non-default address space spatel on Oct 9 2019, 8:14 AM. Authored by
Details Follow-up to D68244 to account for a corner case discussed in: Add one more restriction: if the pointer is deref-or-null and in a non-default (non-zero) address space, we can't assume inbounds.
Diff Detail
Event TimelineComment Actions You want llvm::NullPointerIsDefined(), which also checks for "null-pointer-is-valid" attribute. Comment Actions getPointerDereferenceableBytes should do the above. The tests in the file show it works except there is one missing: define float @matching_scalar_smallest_deref_addrspace(<4 x float> addrspace(4)* dereferenceable(1) %p) { ; CHECK-LABEL: @matching_scalar_smallest_deref_addrspace( ; CHECK-NEXT: [[BC:%.*]] = getelementptr inbounds <4 x float>, <4 x float> addrspace(4)* [[P:%.*]], i64 0, i64 0 ; CHECK-NEXT: [[R:%.*]] = load float, float addrspace(4)* [[BC]], align 16 ; CHECK-NEXT: ret float [[R]] ; %bc = bitcast <4 x float> addrspace(4)* %p to float addrspace(4)* %r = load float, float addrspace(4)* %bc, align 16 ret float %r } site note: The CanBeNull is commonly used as _or_null flag, not to indicate the actual null pointer. That is why the test should result in the inbounds even though the pointer "can be null" but it is for sure "deref". I think this is fine but I want to hear if people agree. Comment Actions Patch updated: Comment Actions Did I miss a message? I copy/pasted at line 92 of the test file (no diff from the code change): define float @matching_scalar_smallest_deref_addrspace(<4 x float> addrspace(4)* dereferenceable(1) %p) { ; CHECK-LABEL: @matching_scalar_smallest_deref_addrspace( ; CHECK-NEXT: [[BC:%.*]] = getelementptr inbounds <4 x float>, <4 x float> addrspace(4)* [[P:%.*]], i64 0, i64 0 ; CHECK-NEXT: [[R:%.*]] = load float, float addrspace(4)* [[BC]], align 16 ; CHECK-NEXT: ret float [[R]] ; %bc = bitcast <4 x float> addrspace(4)* %p to float addrspace(4)* %r = load float, float addrspace(4)* %bc, align 16 ret float %r } Comment Actions I did not realize you comited the test separately so I was expecting to see a new test show in the diff. Sorry. LGTM with a request for an additional comment (see below)
|
Could you add one more sentence here please to complement your reasoning: