<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/113668>113668</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[GlobalISel] Divide multiple values by the same value.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
performance,
llvm:globalisel,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davemgreen
</td>
</tr>
</table>
<pre>
SDAG has an optimization that converts multiple divides by the same value into `y = 1/x` and multiplies by y.
https://godbolt.org/z/3qY8dxWGx
```
define dso_local void @test(ptr nocapture noundef %a, double noundef nofpclass(nan inf) %c) local_unnamed_addr {
entry:
%0 = load double, ptr %a, align 8
%div = fdiv fast double %0, %c
store double %div, ptr %a, align 8
%arrayidx1 = getelementptr inbounds i8, ptr %a, i64 8
%1 = load double, ptr %arrayidx1, align 8
%div2 = fdiv fast double %1, %c
store double %div2, ptr %arrayidx1, align 8
%arrayidx3 = getelementptr inbounds i8, ptr %a, i64 16
%2 = load double, ptr %arrayidx3, align 8
%div4 = fdiv fast double %2, %c
store double %div4, ptr %arrayidx3, align 8
%arrayidx5 = getelementptr inbounds i8, ptr %a, i64 24
%3 = load double, ptr %arrayidx5, align 8
%div6 = fdiv fast double %3, %c
store double %div6, ptr %arrayidx5, align 8
ret void
}
```
SDAG:
```
test: // @test
fmov d1, #1.00000000
ldp d3, d4, [x0, #16]
fdiv d0, d1, d0
ldp d1, d2, [x0]
fmul d1, d1, d0
fmul d2, d2, d0
fmul d3, d3, d0
fmul d0, d4, d0
stp d1, d2, [x0]
stp d3, d0, [x0, #16]
ret
```
GISel:
```
test: // @test
ldp d1, d2, [x0]
ldp d3, d4, [x0, #16]
fdiv d1, d1, d0
fdiv d2, d2, d0
fdiv d3, d3, d0
stp d1, d2, [x0]
fdiv d0, d4, d0
stp d3, d0, [x0, #16]
ret
```
We should implement the same thing in GISel.
</pre>
<img width="1px" height="1px" alt=""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