This is an archive of the discontinued LLVM Phabricator instance.

[GlobalOpt] Fix the load types when OptimizeGlobalAddressOfMalloc
ClosedPublic

Authored by scui on Aug 3 2021, 1:14 PM.

Details

Summary

Currently, in OptimizeGlobalAddressOfMalloc, the transformation for global loads assumes that they have the same Type. With the support of ConstantExpr (https://reviews.llvm.org/D106589), this may not be true any more (as seen in the test case), and we miss the code to handle this, This is to fix that.

Hopefully, this is the problem that @saugustine reported in https://reviews.llvm.org/D106589. The test case I added here has the similar msg you have. Please verify. Thanks.

Diff Detail

Event Timeline

scui created this revision.Aug 3 2021, 1:14 PM
scui requested review of this revision.Aug 3 2021, 1:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2021, 1:14 PM
efriedma added inline comments.Aug 3 2021, 1:21 PM
llvm/lib/Transforms/IPO/GlobalOpt.cpp
1000

Why do you need to mess with the way you're iterating over the uses of LI? Calling ConstantExpr::getBitCast() doesn't mess with the use-list of LI.

1004

Is RepValue dead with this change?

saugustine accepted this revision.Aug 3 2021, 2:42 PM

I need to test a little more extensively, but this does appear to fix the issue I had reported, which is good news. Thanks.

This revision is now accepted and ready to land.Aug 3 2021, 2:42 PM
scui added inline comments.Aug 3 2021, 3:11 PM
llvm/lib/Transforms/IPO/GlobalOpt.cpp
1000

I guess I have a preference on for loop. I'll change it back.

1004

Will add code to make use of it like the original code.

scui updated this revision to Diff 363889.Aug 3 2021, 3:19 PM

To address review comments

efriedma accepted this revision.Aug 3 2021, 3:26 PM

LGTM