This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Fix crash in chained BFI combine due to incorrectly RAUW'ing a node.
ClosedPublic

Authored by aemerson on Jun 24 2021, 11:20 AM.

Details

Summary

For a bfi chain like:

a = bfi input, x, y
b = bfi a, x', y'

The previous code was RAUW'ing a with x, mutating the second b bfi, and when
SelectionDAG's CSE code ended up deleting it unexpectedly, bad things happend.
There's no need to RAUW in this case because we can just return our newly
created replacement BFI node. It also looked incorrect because it didn't account
for other users of the a bfi.

rdar://79095399

Diff Detail

Event Timeline

aemerson created this revision.Jun 24 2021, 11:20 AM
aemerson requested review of this revision.Jun 24 2021, 11:20 AM

Change makes sense.

llvm/test/CodeGen/ARM/bfi-chain-cse-crash.ll
38

Can you simplify the testcase so it doesn't have any references to "undef"? That tends to make testcases a lot more fragile.

aemerson updated this revision to Diff 354332.Jun 24 2021, 12:29 PM

Rework test.

efriedma added inline comments.Jun 24 2021, 12:51 PM
llvm/lib/Target/ARM/ARMISelLowering.cpp
14049

Hang on, I'm not sure this is right. At least, it's not obviously equivalent. FindBFIToCombineWith can look through multiple BFI operations. Not sure if we have proper test coverage for this.

aemerson added inline comments.Jun 24 2021, 1:48 PM
llvm/lib/Target/ARM/ARMISelLowering.cpp
14049

Right, looks like FindBFIToCombineWith tries to skip unrelated BFIs, and the one it can combine with is CombineBFI. I still think this change is correct, but there's not enough test coverage here.

Having looked further, I can't actually force it to generate chains of more than 2 BFIs at all, since this DAG combine ends up running in between each attempt, combining them before 3 chained BFIs can exist at all.

efriedma added inline comments.Jun 24 2021, 1:49 PM
llvm/lib/Target/ARM/ARMISelLowering.cpp
14049

If you want to change the code so it can't skip unrelated BFIs, that's probably fine.

aemerson updated this revision to Diff 354372.Jun 24 2021, 3:12 PM

Remove BFI walking code.

This revision is now accepted and ready to land.Jun 24 2021, 4:32 PM
This revision was landed with ongoing or failed builds.Jun 24 2021, 11:36 PM
This revision was automatically updated to reflect the committed changes.