LLVM has good way to test it’s generated IR, you can do that using check, if you come across some code like this in your lifetime:
define void @sub1(i32* %p, i32 %v) {
entry:
; CHECK: sub1:
; CHECK: subl
%0 = tail call i32 @llvm.atomic.load.sub.i32.p0i32(i32* %p, i32 %v)
ret void
}
define void @inc4(i64* %p) {
entry:
; CHECK: inc4:
; CHECK: incq
%0 = tail call i64 @llvm.atomic.load.add.i64.p0i64(i64* %p, i64 1)
ret void
}; is how you define a comments in llvm IR, so that line will be ignored by llvm, but there is FileCheck tool, which is basically pattern matching file verifier.
so this tool basically does pattern matching for us, and we can verify generated IR, if it’s correct or not!
another example:
; CHECK: %0 = load i32, i32* %ptr, align 4
%0 = load i32, i32* %ptr, align 4In this example, the "; CHECK:" line instructs FileCheck to ensure that the following instruction (%0 = load i32, i32* %ptr, align 4) matches the pattern "%0 = load i32, i32* %ptr, align 4".
In summary: The ";check" directive is a way to guide FileCheck in verifying the correctness of LLVM IR code. It’s not a part of the IR itself, but a comment used for testing purposes.
more in depth is here: https://llvm.org/docs/CommandGuide/FileCheck.html#tutorial