I have some problem about DAG

I hope someone can give me some guidance,thanks!
There is the ir i create.

define dso_local i32 @MUL(i64 %x, i32 %y) local_unnamed_addr #0 {
entry:
  %0 = trunc i64 %x to i32
  %conv1 = mul i32 %0, %y
  ret i32 %conv1
}

Then i use llc -march=riscv32 -view-dag-combine1-dags mul.ll

There are places I did not understand.

  • I don’t understand why we need build_pair,the ir show that %0 = trunc i64 %x to i32,Why use two CopyFromReg?
  • I don’t understand the meaning of ch.

If anyone can help me, I would appreciate it,thanks!

This is the very first DAG that’s produced to represent the IR, so no optimization has occurred. Additionally, it’s riscv32 so any 64-bit argument is going to have to be passed in 2 separate (32-bit) registers and reconstituted to create the i64 value that’s in the IR.

It’s called the “chain” argument and it’s there to represent ordering that’s not captured strictly by register dataflow. Usually most importantly, reads and writes to memory within a block need to happen in the correct order so any of those operations don’t overwrite each other.

In this particular case copies to and from specific physical registers need to happen before the operations that use them. You have to copy the arguments out of registers before they’re used, and into the return register before the RET_FLAT that actually does the return.

1 Like

thanks!