<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJy9VU1v2zAM_TXKRUhgS3bdHHxomg3bYZfttFPh2LStQZYMfTRtf_0o28m0tA2GDRhgyZb4RNIkH3XQzXPZOzdawu8I-4hPJcUjsI2Uj8NGmw53asDpBcdxLb6LryTZk-Runq2moqVHoLUeRiGBul5Y2npVO6FV0BmByU2yPNOygVYooIIzSrLEpQ9eugeLIyHsdtpl-RNh93T5NjDKqoYBlHuQ-viOpBddT9iWkmI3m6EB4RJK-J6KehgpmqCx-iTGpRPOgoQaUel89u-ciLSyX9b9hfWbPOc3EXZ24Embk3UWUM54iEDmtZdp5EocNZeezhk4WzZLQor9m5mZ50pq1VnRLEl1YB1tDBaHuZ5XwrhQtfR4kPB76xqhNz3hH-IjXlnRKWjoRdrP-1X4hfPq8NuqxvwSvov1CeXoUAmFKh61aC4KYDQob1FGGEYz9yS_V9Pn_aV9NhcETmkwEtu5GivXA9XejR5DbCkK0wuAHp0YxItQHQ3YE0Oot2FLKOuQQYfAByRTh5kKMb8eZwMd9Aap80P3at3rAQK--IBE3eujkrpqLGEZRdN0HVtotUZ60_U3utZ0vejmO_pFN17C5_1UXIQVMw4_Tlz3poaHFmmuqgEWFDuhWOzq_-R2-mfUjjhou9cczCMov06v9519ipRkr5Wwq_91FvE3GJtdVOGfJv9Kzc4t-1SRS4Eivc7dO3DOnuQ2pDzuASg1YDGvFss3lDzDQQ8QDkyEgya21mqvkMjPoR4-Vc56BXYUNfK8WHpLBwpM5QCbG9vRu-kaWvyv63BMeaVHqUewdNWUvNnybbWqvOu1Ked4rLyRF9dZJ1zvDxv8WVyES215rUejf2BqcCms9YDR-phzzNGqL1nWJmldtTxti6pNGNzygrVVluXsljdZvZLVAaQtSb7DuldwpJOKwIF8v_p3D0TJEsaSNC3SAnfYpkkhyyDPt3WW3RTpFoMB2O7k-ZZemXJSefCdRaEU1tlfwspOnRMmh9FDJ5yEchD2dGs3HnOr4za0mlwqJ39-AsdsXMU>53252</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
miscompile due to instcombine
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
regehr
</td>
</tr>
</table>
<pre>
https://alive2.llvm.org/ce/z/w-iYiR
so if we compile this function:
```
define i32 @t1_ult_slt_0(i32 %x, i32 %replacement_low, i32 %replacement_high) {
%t0 = icmp slt i32 %x, 0
%t1 = select i1 %t0, i32 %replacement_low, i32 %replacement_high
%t2 = icmp ult i32 %x, 65536
%1 = xor i1 %t2, true
%r = select i1 %1, i32 %x, i32 %t1
ret i32 %r
}
```
alongside this test driver:
```
#include <stdio.h>
unsigned t1_ult_slt_0(unsigned a, unsigned b, unsigned c);
int main(void) {
printf("%u\n", t1_ult_slt_0(2, 0, 1));
}
```
the output is `1`
optimizing the function using instcombine we get this:
```
regehr@john-home:~/Downloads$ opt -instcombine foo.ll -S -o -
; ModuleID = 'foo.ll'
source_filename = "foo.ll"
define i32 @t1_ult_slt_0(i32 %x, i32 %replacement_low, i32 %replacement_high) {
%1 = icmp slt i32 %x, 0
%2 = icmp sgt i32 %x, 65535
%3 = select i1 %1, i32 %replacement_low, i32 %x
%4 = select i1 %2, i32 %replacement_high, i32 %3
ret i32 %4
}
regehr@john-home:~/Downloads$
```
compiling the optimized function, using the same test driver, results in `2` being printed
found by @Hatsunespica's test generater + Alive2
cc @nunoplopes
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VUtzmzAQ_jXyRWMPCDDxgUNsp9MeemlPPWUwWoMyQmL0iNP8-q4AO6qTejo9dMbISPvtg939VgfNf1adc4Ml2T1hn_BXS_EMbCXlc7_SpsWTBnB5xee0FD_EN5LsSXI_rVZTcaQnoI3uByGBuk5YevSqcUKrYDMCk3Uy_8Yth6NQQEXGKMkTlz566R4tPglhd-MpK14I29H53cAg6wZ6UO5R6tMfJJ1oO8I2lJTbyQ0NCJdQku2paPqBogsam09iXDriLEhoEJVOuv8WRGSVvXn3V97XRZGtI-wUwIs2Z-8soJzxEIHM-yjTKJQ4ay496xm4eDZzQcr9h5WZ1lpq1VrB56I6sI5yg81hbteVsEyoRnpUJNnOOi70qiPZQ6zilRWtAk6vyn45r8MnXHaH33YN1pdk29ieUI72tVBo4lkLftUAg0H5EWWEYTYLT4qdGl931_7Z1BC4pMFJ7OdmrlwHVHs3eEyxpShMrwB6cKIXr0K1NGDPDKHehiOhrEMGHQIfkEwtVirk_HaeDbTQGaTOk-7UstM9BHz5gETd65OSuuaWsJyia7qMPRy1RnrT5Xe61HQ528629KvmXsKX_dhchJUTDl_OXPemgccj0lzVPcwodkaxONT_ye3076gdcdC27zlYRNDsNr3-HOxLZCR_b4Td_K6LKPuAsflVF_5t8W_07DSyzx05NyjS6zK9A-fsWW5DyeMZgFIDFutqsX1DyzN86AGCwkg44LG3o_YKifwz9MPn2lmvwA6iQZ6X82xpQYGpHeBwY1t6P15Dc_xNE9SUV3qQegBLF7zK-Cbb1AsnnISqF_Z8A3GPceqYUgtv5NUl1wrX-cMKAbgJV938txyMfsKC4VZY6wFz-KnIsHKLrkpzvsnZutjcNXcbSMsiXwPwLOF35YGzMl_I-gDSVqTYIhsUnOhoIjCj2C9ExRLGkjQtUTNjbMVTyHMoik2T5-sy3eAHAo4webl5F6YaQzr41qJQCuvsm7C24zSE0R3ar73rtKmmvliMnqsx8l_PnUbq">