[LLVMdev] Copy Instructions?
David Greene
dag at cray.com
Tue Jan 27 14:54:04 PST 2009
There is no register-to-register copy instructions in LLVM. I've found a bug
in mem2reg (LLVM 2.3 but it doesn't appear to be fixed in trunk either) and a
copy instruction seems to be the easiest way to fix it.
Consider this code coming into the RenamePass phase of mem2reg.
"*" in the phi means we haven't added that incoming value yet.
// x.0 = ...
// y.0 = ...
//
// do
// x = phi(x.0, *)
// y = phi(y.0, *)
// [...]
// store x -> y
// store expr -> x
// end do
//
// We are updating both phis to add a value from a back edge
// When we saw the first store we set IncomingVals[y] to x.
// When we see the second store we need to create a
// temporary t = x before the second store and set
// IncomingVals[y] to t. Otherwise y's phi will pick up the
// new value of x (expr) rather than the old, proper one.
This bug triggers on a code we have here. I've been unable to successfully
bugpoint it as bugpoint croaks with a bad_alloc exception. We're in the midst
of upgrading to 2.4 so I will re-try bugpoint then. The above pseudocode
represents the situation adequately.
How do I go about creating the copy t = x? I don't want to use an add with a
zero constant because it may not be optimized in all circustations (floating
point, for example).
In this particular example another solution would be to reorder the phis but I
don't think that will work in the general case.
-Dave
More information about the llvm-dev
mailing list