<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/86107>86107</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] why is debug information not retained on store to null instruction
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
quic-asaravan
</td>
</tr>
</table>
<pre>
Debug information not attached to the "store to null" instruction inserted in InstCombinePass to mark unreachable code.
cpp code which generates store to null after instcombinePass (test.cpp):
```
void *def;
#define s_node &def
typedef enum {
A,
B,
C,
D,
E
} enum_type;
typedef struct {
void *field1;
} struct_1;
typedef struct {
struct_1 *field1;
void *val;
} struct_2;
typedef struct s {
struct s *prev, *next;
struct_2 *r;
void *val;
} struct_3;
void foo();
void bar();
void foo1();
void bar1(struct_2 *val);
static unsigned int baz( struct_3 *L )
{
return ( L->val != L->r->field1->field1 );
}
static enum_type baz1( struct_2 *r )
{
if ( !r )
{
return A;
}
if ( r->field1 )
{
return B;
}
if ( s_node == r->val )
{
return C;
}
if ( r->val )
{
return D;
}
return E;
}
static unsigned int helper( struct_2 *r,
enum_type type )
{
return ( type == baz1( r ) );
}
void F( struct_3 *pool, struct_3 *link);
struct {
struct_3 *r;
struct_3 p;
} struct_4;
#define NULL nullptr
#define VALIDATE(x)
void foo( void )
{
struct_3 *val;
struct_3 *next_val;
struct_3 sen;
bar();
val = struct_4.r;
sen.next = val;
sen.prev = NULL;
if ( val )
{
VALIDATE( NULL == val->prev );
val->prev = &sen;
}
/* First, remove all the aliases/placeholders */
while ( val )
{
next_val = val->next;
if ( helper( val->r, B ) ||
baz( val ) )
{
val->prev->next = next_val;
if ( next_val )
{
next_val->prev = val->prev;
}
F( &struct_4.p, val );
}
val = next_val;
}
/* Now remove all the remaining links */
val = sen.next;
while ( val )
{
next_val = val->next;
val->prev->next = next_val;
if ( next_val )
{
next_val->prev = val->prev;
}
bar1( val->r );
F( &struct_4.p, val );
val = next_val;
}
struct_4.r = sen.next;
VALIDATE( NULL == struct_4.r );
foo1();
}
```
The above code is compiled with clang (compiled at SHA - 10451ded6d7ef799569652dfce81653d37f167b5)
`clang++ -g -O2 -mllvm -print-after-all -mllvm -filter-print-funcs="_Z3foov" test.cpp -c`
```
.
.
.
*** IR Dump After InstCombinePass on _Z3foov ***
; Function Attrs: mustprogress
define dso_local void @_Z3foov() local_unnamed_addr #0 !dbg !49 {
.
.
lor.lhs.false: ; preds = %_ZL6helperP8struct_29enum_type.exit
call void @llvm.dbg.value(metadata ptr %val.058, metadata !106, metadata !DIExpression()), !dbg !113
store i1 true, ptr poison, align 1 **<======== Debug Information missing ========>**
br i1 poison, label %if.end15, label %if.then7, !dbg !114
.
.
```
I made a change which retains debug information (https://github.com/llvm/llvm-project/pull/86105) when "store to null" instructions are inserted in InstCombinePass.
Any specific reason not to have debug information attached to "store to null" instruction?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUWFuv6roR_jXmZQQiDhB44IHLQl3S0ulRe9qH84KcxCHuCXZqO6y9--urcW5OCHvvhaKQ-DLzzcw349jMGHGTnO_J-kjW5xmrbK70_r-VSObMMM0eTM5ilX7fn3lc3UDITOk7s0JJkMoCs5YlOU_BKrA5B0KpsUpzfJdVURBKQUhjdZW4OUIari1PQUh4l8ae1D0Wkv_OjMEpd6b_gkpqzpKcxQWHRKV8QZZnsjzU96QsXSN85iLJ4cYl18xyAwO1wDLLtdOceBoI3Vpu7CIpS0J3JDz4kslm2Vzu9aFECoQeUp6R8NgMoWHKMyE5mKtEEIRusN-TYr-XPOUZcFndgUTNxAOhp_rp2D2duqdz9_TWiIrOTsAVpfXaBwpqn_YqAABazJngRRr0E6NzM_wa_LK0dsKEvF7RgxVTWuiPtZhnPdhGD6XmD0JP-Cj5N-spbAVjl_51IOEIiBueKUXo1hHg6DXHTE81Z0oFL4Zjuw8MQXjD6ruxzIoEKukSDYlvIWb_I3Tb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