The intrinsic instructions always have an number in the end, what’s meaning of it?
For example, %2 = call <2 x double> @llvm.x86.sse2.sqrt.pd(<2 x double> %1) #2
What does this #2 mean? Can I ignore it when I create the instruction? Thanks.
The #2 refers to a set of attributes. Attribute sets are given unique numbers. You should see them listed in the IR, somewhere after the functions.
I believe attributes are attached after the instruction is created. They generally apply to functions (and calls), and not to most instructions.
Is this field mandatory? or do I have to create the attribute if I create a call for the intrinsic function?
Usually attributes on call sites are completely unnecessary. They are
things like 'readnone' or 'nounwind', which are optimization hints. There
are some parameter attributes like 'byval' and 'inreg' that are mandatory,
but they are not typically used on intrinsics.