[LLVMdev] Folding cast of a global address to boolean
Morten Ofstad
morten at hue.no
Thu Jan 6 08:17:32 PST 2005
I noticed that folding a cast of a global address to boolean doesn't
work like I expected - there is a comment in the code that casts of
external symbols should not happen, but I don't understand the rationale
for this.
// FIXME: When we support 'external weak' references, we have to prevent
// this transformation from happening. In the meantime we avoid folding
// any cast of an external symbol.
if (!GV->isExternal())
return ConstantBool::True;
This particular transformation is quite important for me because I have
some symbols which are either ConstantPointerNull or a GlovalVariable
depending on which context the program is compiled in. This is used to
implement a kind of conditional compilation, and I'm relying on the
constant folding to remove branches in my code. I tried to change the
linkage type of the GlobalValue, but that's not what the isExternal()
function checks so it did not have any effect.
If I understood better why this is disabled, maybe I can fix it.
Otherwise I will have to implement the conditional compilation as part
of the code generation and that will be quite a bit more complicated.
m.
More information about the llvm-dev
mailing list