<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Times New Roman", Times, serif;">Hi,</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Times New Roman", Times, serif;">I used 2 different compilers to compile the same IR for the same custom target.</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Times New Roman", Times, serif;">The LLVM IR code is </span>
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Courier New", monospace;">define i32 @_Z9test_mathv() #0 {</span><span><br>
</span>
<div><span style="font-family: "Courier New", monospace;">  %a = alloca i32, align 4</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  %1 = load i32, i32* %a, align 4</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  ret i32 %1</span><br>
</div>
<span style="font-family: "Courier New", monospace;">}</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Times New Roman", Times, serif;">Before instruction selection, the Selection DAGs are the same:</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Courier New", monospace;">Optimized legalized selection DAG: %bb.0 '_Z9test_mathv:'</span><span><br>
</span>
<div><span style="font-family: "Courier New", monospace;">SelectionDAG has 7 nodes:</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  t0: ch = EntryToken</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">    t4: i32,ch = load<(dereferenceable load 4 from %ir.a)> t0, FrameIndex:i32<0>, undef:i32</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  t6: ch,glue = CopyToReg t0, Register:i32 $r4, t4</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  t7: ch = UISD::Ret t6, Register:i32 $r4, t6:1</span></div>
<div><span style="font-family: "Courier New", monospace;"><br>
</span></div>
<div><span style="font-family: "Courier New", monospace;"><br>
</span></div>
<div><span style="font-family: "Times New Roman", Times, serif;">But after it, one has 1 more node than the other</span></div>
<div><span style="font-family: "Courier New", monospace;"><br>
</span></div>
<div><span style="font-family: "Times New Roman", Times, serif;">compiler 1</span><br>
</div>
<span></span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Courier New", monospace;">===== Instruction selection ends:</span><span><br>
</span>
<div><span style="font-family: "Courier New", monospace;">Selected selection DAG: %bb.0 '_Z9test_mathv:'</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">SelectionDAG has 8 nodes:</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  t0: ch = EntryToken</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">      </span><span style="font-family: "Courier New", monospace; color: rgb(200, 38, 19);">t1: i32 = add TargetFrameIndex:i32<0>, TargetConstant:i32<0></span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">    t4: i32,ch = LDWI<Mem:(dereferenceable load 4 from %ir.a)> t1, t0</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  t6: ch,glue = CopyToReg t0, Register:i32 $r4, t4</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  t7: ch = JLR Register:i32 $r4, t6, t6:1</span></div>
<div><br>
</div>
<div><br>
</div>
<div><span style="font-family: "Times New Roman", Times, serif;">compiler 2</span></div>
<div><span style="font-family: "Courier New", monospace;">===== Instruction selection ends:</span><span><br>
</span>
<div><span style="font-family: "Courier New", monospace;">Selected selection DAG: BB#0 '_Z9test_mathv:'</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">SelectionDAG has 7 nodes:</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  t0: ch = EntryToken</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">    t4: i32,ch = <span style="font-family: "Courier New", monospace">
LDWI</span><Mem:LD4[%a](dereferenceable)> </span><span style="font-family: "Courier New", monospace; color: rgb(200, 38, 19);">TargetFrameIndex:i32<0>, TargetConstant:i32<0></span><span style="font-family: "Courier New", monospace;">, t0</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  t6: ch,glue = CopyToReg t0, Register:i32 %<span style="font-family: "Courier New", monospace">$r4</span>, t4</span><br>
</div>
<div><span style="font-family: "Courier New", monospace;">  t7: ch = <span style="font-family: "Courier New", monospace">
JLR</span> Register:i32 %<span style="font-family: "Courier New", monospace">$r4</span>, t6, t6:1</span><br>
</div>
<span></span><br>
</div>
<span></span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Times New Roman", Times, serif;">In the first case, node t1 is a separate node whereas
</span><span style="font-family: "Times New Roman", Times, serif;">in the second case, t1 is inside t4</span><span style="font-family: "Times New Roman", Times, serif;">. What difference in implementation could explain this difference in behavior? Where in
 the code should I look into? <br>
</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Times New Roman", Times, serif;">(Note that "LDWI" is an instruction that adds up a register and an immediate and loads the memory content located at the address represented by the sum into a register)<br>
</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Times New Roman", Times, serif;"><br>
</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "Times New Roman", Times, serif;">Thanks.</span><br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
</body>
</html>