The return value of performScalarPRE() at its call site in function bool GVN::processNonLocalLoad(LoadInst *LI) is not taken into account. This patch fixes the issue.
Details
Diff Detail
Event Timeline
Thanks for the patch, there is a broken test in the validation with this patch: test/Transforms/GVN/pre-gep-load.ll
Can you have a look?
Note: It is very likely that the test just need to be updated, but you may want to be sure why.
Okay I'll take a look.
Le vendredi 11 décembre 2015, Mehdi AMINI <mehdi.amini@apple.com> a écrit :
joker.eph added a comment.
Note: It is very likely that the test just need to be updated, but you may
want to be sure why.
After studying the test case that failed and GVN.cpp, I found that int the function processNonLocalLoad(LoadInst *LI), not taking the return value of performScalarPRE(I) into account is actually correct. It's not a bug because performScalarPRE(I) is just a step of analyzing when the first operand of the LoadInst is a GEP, which means the LoadInst follows a GEP. performScalarPRE(I) can return true (the GEP is thus eliminated) whereas the LoadInst is not eliminated and thus processNonLocalLoad(LoadInst *LI) should return false.
I was about to tell you what you just discovered :)
THe real issue here is that we are inconsistent in what the return values
of these functions mean.
processNonLocalLoad is not returning whether it changed, but whether it
deleted the load.
processLoad in turn is also returning whether it deleted the load.
However, processInstruction then uses this to determine if the function has
changed ...
If you want to make these functions return whether anything changed, i'm
not opposed, but you have to carefully go through the logic separate the
two things it uses the return values for ;)