InstCombine debugging reference

Instruction Combine is a crucial pass occurring in the middle of the pipeline. It consolidates redundant instructions and while doing that it doesn't always get the Debug Info right.

Code structure

The pass is split into many different files. The class definition along with the definition of the instruction work-list is in llvm/include/llvm/Transforms/InstCombine while the implementation lies in llvm/lib/Transforms/InstCombine. The main cpp file is /home/gramanas/code/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

The pass runs on a function level.

Debugging

In order to see what the pass is doing step by step use this:

opt -debug-only=instcombine -instcombine sample.ll

Example

The following llvm-ir snippet:

define <2 x i64> @test3(<2 x i64> %A) {
  %trunc = trunc <2 x i64> %A to <2 x i32>
  %and = and <2 x i32> %trunc, <i32 23, i32 42>
  %zext = zext <2 x i32> %and to <2 x i64>
  ret <2 x i64> %zext
}

gets reduced to this:

define <2 x i64> @test3(<2 x i64> %A) {                                                                                                                                              
  %and = and <2 x i64> %A, <i64 23, i64 42>                                                                                                                                          
  ret <2 x i64> %and                                                                                                                                                                 
}

after running instcombine on it.

We are left with two dbg.value intrinsics missing.