difference between replaceAllUsesWith and replaceUsesOfWith?

Why is the first for loop not equivalent to the second?

Thanks,
Rob

Hi Rob,

I think this is incorrect since the use_iterator is defined as:

`typedef value_use_iterator<User> use_iterator;`

and indeed `ui->getUser();` is not a callable function on a User. What am I
missing?

-Rob

To make this clearer, I’ve reposted the loops below, replacing dyn_cast with cast. I’ve also added the assertion, which triggers in the bottom loop, but not the top.

-Rob

I think this is incorrect since the use_iterator is defined as:

`typedef value_use_iterator<User> use_iterator;`

and indeed `ui->getUser();` is not a callable function on a User. What am I
missing?

Ah, looks like this has changed this year. What I said applies to
trunk; you may be right there about 3.4 or earlier (looks plausible
from the key commit).

Another problem might be that User::replaceUsesOfWith only works in
limited situations if the User is a Constant. But I'd expect that to
fail with an assertion (assuming your LLVM has been built with
assertions enabled, of course).

Do you have (preferably as simple as possible) IR module that shows
the replacement failure?

Cheers.

Tim.

Ahh ha! I believe that User::replaceUsesOfWith modifies the use list, which probably invalidated the use_iterator and caused my code to miss some of the uses. The following works great! (I’ll spare you the details about what I am actually trying to do here, unless you really want to know more.)

Thanks,
Rob

Ah yes, that would explain it. Sorry I wasn't much help.

You could also safely increment the iterator before removing the use,
I think (which has the benefit of not being a quadratic algorithm).

Cheers.

Tim.