This results in an incorrect offset for %add.ptr = getelementptr inbounds %"struct.std::pair", ptr %4, i32 %__n since we'd now just add %.sink1 bytes (where %.sink1 = %__n which is the second argument), whereas before we'd add %__n * 8 bytes (where 8 is the sizeof %"struct.std::pair").
The above IR when piped through gvn-sink via
./bin/opt < /tmp/repro.ll -passes=gvn-sink -S
produces:The GEP in the result is incorrect. Prior, the GEPs were
but now it's
This results in an incorrect offset for
%add.ptr = getelementptr inbounds %"struct.std::pair", ptr %4, i32 %__n
since we'd now just add%.sink1
bytes (where%.sink1 = %__n
which is the second argument), whereas before we'd add%__n * 8
bytes (where 8 is the sizeof%"struct.std::pair"
).The before ASM is:
but the after asm is:
The GEP should not be a candidate for sinking.