<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114182>114182</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] wrong negation of PHI
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bongjunj
</td>
</tr>
</table>
<pre>
The follow lines are executed:
https://github.com/llvm/llvm-project/blob/9a7519fdb39f21a807189e1ed06826b43db929e1/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp#L308-L326
Alive2 report: https://alive2.llvm.org/ce/z/NmasVn
```llvm
----------------------------------------
define i32 @pr50308.2(i1 %c1, i32 %v1, i32 %v2, i32 %v3) {
entry:
br i1 %c1, label %cond.true, label %cond.end
cond.true:
%#0 = sext i1 %c1 to i32
%#1 = xor i32 1, %#0
%#2 = add i32 %#0, %v1
%#3 = and i32 %v1, %#2
%#4 = sdiv i32 %#3, %#1
br label %cond.end
cond.end:
%cond = phi i32 [ %#4, %cond.true ], [ 0, %entry ]
%sub = sub nuw i32 %v3, %cond
ret i32 %sub
}
=>
define i32 @pr50308.2(i1 %c1, i32 %v1, i32 %v2, i32 %v3) {
entry:
br i1 %c1, label %cond.true, label %cond.end
cond.true:
%#0 = add i32 %v1, 4294967295
%#1 = and i32 %v1, %#0
%.neg = ashr exact i32 %#1, 1
br label %cond.end
cond.end:
%cond.neg = phi i32 [ %.neg, %cond.true ], [ 0, %entry ]
%sub = add i32 %cond.neg, %v3
ret i32 %sub
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source
Example:
i1 %c1 = #x1 (1)
i32 %v1 = undef
i32 %v2 = poison
i32 %v3 = #xffffffff (4294967295, -1)
Source:
>> Jump to %cond.true
i32 %#0 = #xffffffff (4294967295, -1)
i32 %#1 = #xfffffffe (4294967294, -2)
i32 %#2 = #xffffffff (4294967295, -1) [based on undef value]
i32 %#3 = #x00000000 (0) [based on undef value]
i32 %#4 = #x00000000 (0)
>> Jump to %cond.end
i32 %cond = #x00000000 (0) [based on undef value]
i32 %sub = #xffffffff (4294967295, -1)
Target:
>> Jump to %cond.true
i32 %#0 = #xffffffff (4294967295, -1) [based on undef value]
i32 %#1 = #x00000000 (0) [based on undef value]
i32 %.neg = #x00000000 (0)
>> Jump to %cond.end
i32 %cond.neg = poison
i32 %sub = poison
Source value: #xffffffff (4294967295, -1)
Target value: poison
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcV11v6ygT_jXkBiWCwU7ii1y0TaP3vDo6u-pWe4_NOHHlQAQ4TffXr4w_gtvz0Wq7N2tVqWAenhmGh_FYOlftNeKGpLck3c5k4w_GbnKj90-NfprlRr1sHg9IS1PX5pnWlUZHpUWKFywaj4qIG8K2hN0cvD-5dgQ7Art95Q9NvijMkcCurs_Dv_nJmicsPIFdXpucwC6Tq5RnpcpFVgKXa7bi6ww5KrZcwzJPhMozyJBHPFW77tFK7Upjj47A7ot2_s4c80rjdPQN99IbuyhOJwLiq2Dr-VcByy7kt783dXVGoBZPxnoibuh0VzKYF20cC2P3BHZF6-8vArtvR-n-1BPGJev-Qthhav7Op0MrLCuNtBJAScJONmWCrRdAYF1xSiAtOIG7zgzpeTKAeCAIZJSsbjtW1N6-jKdGaW5pTFfLHOswNFotvG3w7SxqFW_0iryyEkgJCEaJ2FKHFz_6oN60gU1xPOAuxoaYQxw9wRQHASeVGvYWIB36zKdY0WG1mmaoJ5piky5OVZ0jYnGF8yhZv05FOzfJRDsbPJwOVecgvR08907GHFKSbsNcekuHrYUjC4Yrp2vyLugmp7p5jg97JBzgFv1gd03ex7vq2YjYEnH_31JcpJAuygSyJFuuIEu_J7wfiCQW30LjvsO6g6V4kYWPpBIWfYJIRi-vhNLO_1OhRDkZXA03R7xLKGPBlb4ymiqDThNYeXpGW5UvBHi8yfuHh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