[llvm] [InstCombine] Retain debug information on store to null instruction (PR #86105)
Abinaya Saravanan via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 21 10:07:16 PDT 2024
quic-asaravan wrote:
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 - https://github.com/llvm/llvm-project/commit/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
.
.
```
Any specific reason not to have debug information attached to "store to null" instruction?
https://github.com/llvm/llvm-project/pull/86105
More information about the llvm-commits
mailing list