<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63525>63525</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Under the O2 optimization level, compiler_rt has an error about instcombine optimization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zhusihang
</td>
</tr>
</table>
<pre>
When compiling compiler-rt/lib/profile/InstrProfilingMerge.c:125:20, bad instruction folding by foldGEPICmp during instcombine.
```
origin instruction:
%cmp = icmp ult ptr %add.ptr6, %add.ptr4, !dbg !153
new instruction after foldGEPICmp:
<badref> = icmp slt i64 %mul, 0
which corresponds to code or function is:
if (SrcNameStart < SrcCountersStart)
^
```
Unsigned comparison (aka. SrcName Start < Src Counter Start) becomes signed comparison (aka. Header->CountersSize * __llvm_profile_counter_entry_size() < 0).
The original overflow judgment becomes a comparison of the second parameter of the gep instruction with 0. The result is always false, causing the corresponding overflow judgment semantics to fail.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VMGOpDYQ_RpzKQ0CG-juA4fOzHSyhyQrTVY5toxdgDfGRmUzrZmvj8zQO91KVkLCVYb3XrmeS4ZgBofYsvoXVj9lcomjp_Z9XIIZpRuyzuu39u8RHSg_zcYaN2wrpAeKjJ-s6Rg_zeR7Y5Hx0xcXIn1dQ-OG35EGzBUTx5LXTBx5wfgjdFKDSd8tKhrvoPdWJ-TubV3--vz1y-M0g14oZdOXyk-dcZiz4okVR9YU27OG4MkMxt1CMnHc9oDxWk0zMPEEJi0WG2GOlPJS63yO1CRNn2H1EZa6G9KrrMUVyuHlTrfsI9Kt5Fta8dhJTdgz8fxJHmwE01SJbVpsIrrWcBmNGkF5IgyzdzpA9KC8RvAE_eI-GE24oTA9ML5_IfWHnPAlSoqJFV5IPfrFRaSwJhk_bH-w-vl_D_CbW22g19ZKMsG7hCz_kTls8HCHDxsBXAmgQ-UnDPBzoN9QaqQHJp5_qDPvCIwf4Xy29nU6byY6q4_9M7pIb-dg3pHxfSJJ7AXjhxw-dP814tZ7acG_IvXWX-D7oocJXfyhSd7K8T3EESGg8k7DLElOmCrZ8gPOdy2-mDhCkUOiIgzJPCaAtBf5FqCXNmBqopJLSFZNCJ8tTJn_qgo4SReNWhvcS2PzTLdCH8RBZtiWzX6329d7wbOxLSutpdhVsthXyEVRVGLH-0o0vKzVHnlmWl5wUTS8KQUXdZl3u66WjWqUKvlB95xVBU6JIx1w7mnITAgLto2oeZ1Z2aEN6-XnfDV32mScp1lAbfrnoVuGwKrCmhDDJ0o00WL7zWmkteg_Ofg5msm8y_XYLL7iau_rsDhThFEGkA6QyBPIzi_x9m7fAWQL2XaMcV79zk-MnwYTx6XLlZ_S1LGv19fDTP47qjSLVvmB8dNa3r8BAAD__9cnmc4">