<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121459>121459</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] GEPNoWrapFlags is propagated incorrectly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:instcombine
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
dtcxzyw
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
Alive2: https://alive2.llvm.org/ce/z/3ME7S7
```
define ptr @src(i1 %c, ptr %p) {
br i1 %c, label %if, label %else
if:
%gep1 = getelementptr inbounds i32, ptr %p, i64 1
br label %join
else:
%gep2 = getelementptr i64, ptr %p, i64 2
br label %join
join:
%phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]
%gep = getelementptr i32, ptr %phi, i64 1
ret ptr %gep
}
```
```
----------------------------------------
define ptr @src(i1 %c, ptr %p) {
#0:
br i1 %c, label %if, label %else
else:
%gep2 = gep ptr %p, 8 x i64 2
br label %join
if:
%gep1 = gep inbounds ptr %p, 4 x i64 1
br label %join
join:
%phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]
%gep = gep ptr %phi, 4 x i64 1
ret ptr %gep
}
=>
define ptr @src(i1 %c, ptr %p) {
#0:
br i1 %c, label %if, label %else
else:
br label %join
if:
br label %join
join:
%#1 = phi i64 [ 4, %if ], [ 16, %else ]
%#2 = gep inbounds nuw ptr %p, 1 x i64 %#1
%gep = gep ptr %#2, 1 x i64 4
ret ptr %gep
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source
Example:
i1 %c = #x0 (0)
ptr %p = null
Source:
>> Jump to %else
ptr %gep2 = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010
>> Jump to %join
ptr %phi = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010
ptr %gep = pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014
SOURCE MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 > size: 0 align: 1 alloc type: 0 alive: false address: 0
Block 1 > size: 0 align: 1 alloc type: 0 alive: true address: 1
Target:
>> Jump to %else
>> Jump to %join
i64 %#1 = #x0000000000000010 (16)
ptr %#2 = poison
ptr %gep = poison
Source value: pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014
Target value: poison
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVk1v4zYQ_TXjC-GAGkqRdfBB8UfRdjcukhRFTwUt0Ta3lCiQlDfOry9IybGVxsk2xbaGAYsccebNezP0cGvlthZiCskNIJaueHw6fAVESOYj3rqdNtN-c7TW5WGaK7kXCCwnO-caCywHXAIuedi_UmpfXWmzBVwWAnD5BLhknxfpfQo0h2vaf2leio2sBWmcIRBTawrAiYwIYFIAzrp9TBrAjEB6AzQna0POXlB8LZRfyc1gKZQVPhTN5caDoznx21vRRATYnGyFE0pUonY-hKzXuq1LSyTDYdgZkdcxicL5tTn5_6Jl3fkPkQYR8LUI1_FrjvENx-Hp5LjZyeDX_wY3yc0xI-8tUEAgmYfFsw17m0cZrCeYr6Ecpr-TQwKMcEfbVjQeZTp_oefgmebjb_x8pBIAGT3y80-L4ky0oWbNQKIJeXxXpkv11Zyq6txl3Lt8q6T-I-WbF0IPoV0Sm82BLf5Hvd6V4V1OARNAFj1z6nP2vMWvshldXyASkOHfta7brwO9o57UPugbKnh_5yfit2R4MLy2G20q7qSuSamFrQFTR_bCyM0BMOrSXtzdre78Nf3AzVY4Ii2ptBGk0dLqWreWuB2vidWtKXquF4-8alRPd69SwArIHikBnFDADGh-TDMY61ap7vx95-tYv2wBbEF-aquGOH2m6impjsVGy9oJAzipdT1WuuDKs7FWuvjzD1kCm1O_1puNFQ7Y3OuSEcAlycvSCGt9ZXqEg09EL6DoK-PUAd8bxCnfD0VC-k2R4l6D1a93swX5vPi8uvud3D_kD4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