EmitGEPOffset() is improved to avoid generation unneeded operation add 0, Result and return Result instead.
Details
Diff Detail
Unit Tests
Time | Test | |
---|---|---|
360 ms | linux > HWAddressSanitizer-x86_64.TestCases::sizes.cpp |
Event Timeline
Drive by: Tests needed, commit message missing, and we should see if we can avoid 3-5 line assignments.
EmitGEPOffset() is used by instcombine and we do not see the redundant add 0, X instruction because it is immediately optimized out in the same iteration. It prevents a simple lit test for this patch. On the other hand you can see the fix in InstCombinerImpl::OptimizePointerDifference() which changes the code to expect X in place of add 0, X and there is a related test (test/Transforms/InstCombine/sub-gep.ll), which I believe is enough for this small improvement.
Keep in mind that EmitGEPOffset() could be used in other custom passes that might not require subsequent instcombine to run.
I believe we do not have to adjust sources to make them look better being formatted by the clang formatter. We should improve the formatter instead. But this should not prevent this patch to be accepted.
I'm ok to rename the variables for a better look if this is the only thing that is needed for LGTM, though.
and there is a related test (test/Transforms/InstCombine/sub-gep.ll), which I believe is enough for this small improvement.
Is this test changed? It seems to be missing from the diff.
Keep in mind that EmitGEPOffset() could be used in other custom passes that might not require subsequent instcombine to run.
Noted.
I believe we do not have to adjust sources to make them look better being formatted by the clang formatter. We should improve the formatter instead. But this should not prevent this patch to be accepted. I'm ok to rename the variables for a better look if this is the only thing that is needed for LGTM, though.
Let me rephrase. Please avoid assignments over 3-5 lines, it is hard to read.