constantexpr problem

Hi all,
I have got a problem when I used the use_empty() member function while I used a global variable. I erase all the instructions which will use a global variable. Then I called the use_empty() on that global variable. I got no empty because a constantexpr use the global variable. I wonder whether there is any way to erase the constantexpr which is useless to me but occupying the global variable.
best regard!
yours. Tsingray

Hi Tsingray,

    I have got a problem when I used the use_empty() member function while I
used a global variable. I erase all the instructions which will use a global
variable. Then I called the use_empty() on that global variable. I got no empty
because a constantexpr use the global variable. I wonder whether there is any
way to erase the constantexpr which is useless to me but occupying the global
variable.

if G is your global variable, do
   G->replaceAllUsesWith(UndefValue::get(G->getType()));
to replace G with undef in all users of G. You can then safely delete G.

Ciao, Duncan.

GV->removeDeadConstantUsers();

Nick