This is an archive of the discontinued LLVM Phabricator instance.

[NewGVN][PHIOFOPS] Bail out if an operand is in OpSafeForPHIOfOps but it is not safe for the current basic block.
ClosedPublic

Authored by kmitropoulou on Aug 1 2022, 8:37 AM.

Details

Summary

NewGVN tables are not cleared out between the initial run of NewGVN and the verification. In case of phi-of-ops optimization, OpSafeForPHIOfOps goes out of sync between the two runs. One operand might not be safe for one basic block, but it might be safe for one of its successors. In this case, the operand will be added in OpSafeForPHIOfOps map. In verification phase, we reuse OpSafeForPHIOfOps without updating it again. As a result, the operand will be considered safe for phi-of-ops optimization even for the case that it is not. This patch fixes this problem.

Fix for 53807.

Diff Detail

Event Timeline

kmitropoulou created this revision.Aug 1 2022, 8:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 8:37 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
kmitropoulou requested review of this revision.Aug 1 2022, 8:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 8:37 AM
kmitropoulou edited the summary of this revision. (Show Details)Aug 1 2022, 8:50 AM
kmitropoulou added reviewers: asbirlea, nlopes.
foad added a subscriber: foad.Aug 2 2022, 1:22 AM
foad added a comment.Aug 2 2022, 1:28 AM

I am not too familiar with NewGVN, but wouldn't it be simpler and safer to clear OpSafeForPHIOfOps in verifyIterationSettled()? It is inside #ifndef NDEBUG so it doesn't matter too much if it's a bit slower.

llvm/lib/Transforms/Scalar/NewGVN.cpp
2591–2592

"need", "bail out" (no hyphen)

Updating D130910: [NewGVN][PHIOFOPS] Bail-out if an operand is in OpSafeForPHIOfOps but it is not safe for the current basic block.

kmitropoulou retitled this revision from [NewGVN][PHIOFOPS] Bail-out if an operand is in OpSafeForPHIOfOps but it is not safe for the current basic block. to [NewGVN][PHIOFOPS] Bail out if an operand is in OpSafeForPHIOfOps but it is not safe for the current basic block..Aug 2 2022, 1:49 PM
kmitropoulou marked an inline comment as done.

I am not too familiar with NewGVN, but wouldn't it be simpler and safer to clear OpSafeForPHIOfOps in verifyIterationSettled()? It is inside #ifndef NDEBUG so it doesn't matter too much if it's a bit slower.

Good point! Thank you!

asbirlea accepted this revision.Aug 16 2022, 3:42 PM

I don't feel like I fully understand NewGVN either, but it does resolve the issue and the testing I did so far did not reveal any additional issues. Thank you for resolving this!

This revision is now accepted and ready to land.Aug 16 2022, 3:42 PM

Updating D130910: [NewGVN][PHIOFOPS] Bail out if an operand is in OpSafeForPHIOfOps but it is not safe for the current basic block.

Updating D130910: [NewGVN][PHIOFOPS] Bail out if an operand is in OpSafeForPHIOfOps but it is not safe for the current basic block.