Combining LLVM IR
In this recipe, you will learn about instruction combining in LLVM. By instruction combining, we mean replacing a sequence of instructions with more efficient instructions that produce the same result in fewer machine cycles. In this recipe, we will see how we can make modifications in the LLVM code to combine certain instructions.
Getting started
To test our implementation, we will write test code that we will use to verify that our implementation is working properly to combine instructions:
define i32 @test19(i32 %x, i32 %y, i32 %z) { %xor1 = xor i32 %y, %z %or = or i32 %x, %xor1 %xor2 = xor i32 %x, %z %xor3 = xor i32 %xor2, %y %res = xor i32 %or, %xor3 ret i32 %res }
How to do it…
- Open the
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp ...
Get LLVM Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.