This is an archive of the discontinued LLVM Phabricator instance.

[SCCP][PhaseOrdering] Mark Overdefined for loading from null
Needs ReviewPublic

Authored by StephenFan on Aug 8 2023, 9:25 AM.

Details

Reviewers
nikic
Summary

Currently, SCCPSolver preserves the unknown state of lattice value when
solving a load from null. But a unknown state would be replaced as undef
in the end at method 'getConstantOrNull'.

As a comparison, InstCombine creates a non-terminal unreachable to
inform the SimplifyCFG pass inserting an unreachable instruction.

As test file load-from-null.ll shows, The way that InstCombine does is
better than SCCP. By marking it as overdefined, SCCP would not replace
it as undef, and let InstCombine optimize it to just an unreachable.

Diff Detail

Event Timeline

StephenFan created this revision.Aug 8 2023, 9:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 9:25 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
StephenFan requested review of this revision.Aug 8 2023, 9:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 9:25 AM
nikic added a comment.Aug 9 2023, 4:04 AM

What is the original, non-artificial motivation for this?

This will not always be a positive change, because IPSCCP itself may become less effective (e.g. if one of the contributors to a phi is a load from null, we won't be able to ignore that incoming value anymore).

What is the original, non-artificial motivation for this?

It was found when I updated the other SCCP patch D153717. So there is no non-artificial motivation for it.

This will not always be a positive change, because IPSCCP itself may become less effective (e.g. if one of the contributors to a phi is a load from null, we won't be able to ignore that incoming value anymore).

Yes. What this patch does makes IPSCCP solve inter-procedure transformation and phis less effective. Can we make willReturn return false for loading null? Then we can preserve these loading from null instructions in many passes and let instcombine and simplifyCFG to transform it to unreachable and delete some dead blocks.