Mohammad Norouzi via llvm-dev
2016-Feb-05 10:06 UTC
[llvm-dev] replace uses of loadInst with a value
Hi, I need to replace all uses of load instructions with the value of its operand. Here is an example: %16 = load i32, i32* %x %add = add i32 4, %16 In this case, i would like to have the result as: %add = add i32 4, %x and then delete the load instruction. I have tried replaceAllUsesWithValue but i get a type problem. "llvm::Value::replaceAllUsesWith(llvm::Value*): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed." Best, Mohammad -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160205/d5209eff/attachment.html>
serge guelton via llvm-dev
2016-Feb-05 10:21 UTC
[llvm-dev] replace uses of loadInst with a value
On Fri, Feb 05, 2016 at 11:06:50AM +0100, Mohammad Norouzi via llvm-dev wrote:> Hi, > > I need to replace all uses of load instructions with the value of its > operand. Here is an example: > > %16 = load i32, i32* %x > > %add = add i32 4, %16 > > In this case, i would like to have the result as: > > %add = add i32 4, %x > > and then delete the load instruction. I have tried replaceAllUsesWithValue > but i get a type problem. > > "llvm::Value::replaceAllUsesWith(llvm::Value*): Assertion `New->getType() > == getType() && "replaceAllUses of value with new value of different > type!"' failed."Hi Mohammad, i32* %x and i32 4 don't have the same type, and that triggers the assert. If you want to use x as an integer, you should bitcast it, then trunc or zext it depending on the pointer bitwidth... hope it helps
mats petersson via llvm-dev
2016-Feb-05 10:21 UTC
[llvm-dev] replace uses of loadInst with a value
So, you are replacing
add = *x + 4
with
add = x + 4
(where x is still an `int *x`)
Is that really what you want?
On 5 February 2016 at 10:06, Mohammad Norouzi via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> Hi,
>
> I need to replace all uses of load instructions with the value of its
> operand. Here is an example:
>
> %16 = load i32, i32* %x
>
> %add = add i32 4, %16
>
> In this case, i would like to have the result as:
>
> %add = add i32 4, %x
>
> and then delete the load instruction. I have tried replaceAllUsesWithValue
> but i get a type problem.
>
> "llvm::Value::replaceAllUsesWith(llvm::Value*): Assertion
`New->getType()
> == getType() && "replaceAllUses of value with new value of
different
> type!"' failed."
>
> Best,
> Mohammad
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20160205/2fa943c3/attachment.html>