Well, const doesn't guarantee that there's no other non-const pointers that could also modify the memory. It's also legal to cast const away if the underlying memory wasn't constant. So it doesn't really help the compiler to recognize the compiler to realize memory won't change.
(In realistic examples compute_something() would affect code flow and probably take parameters, i.e. wouldn't only be meaningful if it did something with globals. Was too quick to type out the example to think of that.)
-
-
Oh, this is part of a very actual discussion in the committee about contracts and assumptions. You will be able to write an assumption that the object is not changed. And compiler will be able to use it for making an optimization.
-
Hm. Seems somewhat painful to write assumptions about memory not changing. Looks like it'd require copying the to-be-asssumed-unchanging memory, writing an assumption about it not having changed using memcmp() or such, and the compiler to realize that the copy is unnecessary?
- 4 more replies
New conversation -
-
-
I'd even be happy if
@llvmorg and@gnutools were to expose something like LLVM IR's http://llvm.org/docs/LangRef.html#llvm-invariant-start-intrinsic … as builtins. Although I'd prefer something that works across more compilers.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.