Example:
declare noalias i8* @malloc(i64)
define i1 @compare_noalias(i64 %x, i8* %y) {
%m = call i8* @malloc(i64 %x) %r = icmp eq i8* %m, %y ret i1 %r
}
In this case %r must be false because @malloc has the 'noalias' attribute.
Fixes PR38956
Paths
| Differential D52164
[InstSimplify] Fold ne/eq comparison of a pointer produced by a noalias function AbandonedPublic Authored by xbolva00 on Sep 17 2018, 1:26 AM.
Details
Diff Detail
Event TimelineComment Actions Are there tests with comparisons with nullptr? (Also mind the nullptr is valid thingy)
Comment Actions Yes, I will add more tests. Suggestions welcome.
Comment Actions Unfortunately, I don't think that we can do this. noalias semantics only provide information about the overlap of memory accesses using the resulting pointers, in the context of other necessary constraints, and does not strongly constrain the pointer values. For example, it might be that: int *x = malloc(n); free(x); int *y = malloc(n); if (y == x) // should we always fold this to false? printf("malloc reused memory"); Also, what happens if the result is null, and you're comparing to a value which also happens to be null? This revision now requires changes to proceed.Sep 17 2018, 10:52 AM Comment Actions Ok.. so maybe
? Any further caveats? This revision now requires changes to proceed.Sep 17 2018, 11:11 AM Comment Actions int f(int n) { int *x = (int *)malloc(n); free(x); int *y = (int *)malloc(n); return (y == x) ; } This has been already folded to true even before this patch. Comment Actions
But it's not just comparing to a nullptr constant, it's also comparing to another SSA value that, dynamically, is null. Comment Actions
You need to look at how this folding happens? Does it still happen if you actually use the allocation for something? We fold unused allocations away, as I recall. Comment Actions
Yeah. But like the original idea was, we could handle comparison of noalias ptr to ptr pointing to global vars/functions, no?
Revision Contents
Diff 165725 lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/icmp-noalias-pointers.ll
|
Just return i1? I don't think we care about anything else other than the i1.