This is an archive of the discontinued LLVM Phabricator instance.

InstCombine: Can't fold a phi arg load into the phi if the load is from a swifterror address
ClosedPublic

Authored by aschwaighofer on Mar 8 2022, 7:30 AM.

Details

Summary

swifterror addresses are only allowed as operands to load, store, and
calls.

The following transformation is not allowed. It would create a phi with a
swifterror address operand.

%addr = alloca swifterror i8*
br %cond, label %bb1, label %b22

bb1:
  %val1 = load i8*, i8** %addr
  br exit

bb2:
  %val2 = load i8*, i8** %addr
  br exit

exit:
  %val = phi [%val1, %bb1] [%val2, %bb2]

>

%addr = alloca swifterror i8*
br %cond, label %bb1, label %b22

bb1:
  br exit

bb2:
  br exit

exit:
  %val_addr = phi [%addr, %bb1] [%addr, %bb2]
  %val2 = load i8*, i8** %val_addr

rdar://89865485

Diff Detail

Event Timeline

aschwaighofer created this revision.Mar 8 2022, 7:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2022, 7:30 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
aschwaighofer requested review of this revision.Mar 8 2022, 7:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2022, 7:30 AM
fhahn added a subscriber: fhahn.Mar 8 2022, 7:56 AM
fhahn added inline comments.
llvm/test/Transforms/InstCombine/phi-equal-incoming-pointers.ll
581

Looks like this test uses utils/update_test_checks.py to generate the checks. Could you update the test using the script?

Update test checks to use llvm/utils/update_test_checks.py

fhahn accepted this revision.Mar 8 2022, 8:14 AM

LGTM, thanks! This matches the spec in LangRef.

But in general, I'd expect this restriction not being enforced in many other places. Is there a verifier that rejects invalid uses of swifterror?

llvm/test/Transforms/InstCombine/phi-equal-incoming-pointers.ll
620

nit: remove empty lines

This revision is now accepted and ready to land.Mar 8 2022, 8:14 AM
aschwaighofer marked an inline comment as done.Mar 8 2022, 8:14 AM

Yes the LLVM verifier catches invalid uses of swifterror addresses.

Remove empty lines

aschwaighofer marked an inline comment as done.Mar 8 2022, 8:18 AM
This revision was landed with ongoing or failed builds.Mar 8 2022, 9:10 AM
This revision was automatically updated to reflect the committed changes.