This is an archive of the discontinued LLVM Phabricator instance.

[Attributor] Fold terminators before changing instructions to unreachable
ClosedPublic

Authored by baziotis on Mar 6 2020, 3:56 PM.

Details

Summary

It is possible that an instruction to be changed to unreachable is in the same block with a terminator that can be constant-folded.
In this case, as of now, the instruction will be changed to unreachable before the terminator is folded. But, then the whole BB becomes
invalidated and so when we go ahead to fold the terminator, we trap.

Change the order of these two.

Diff Detail

Event Timeline

baziotis created this revision.Mar 6 2020, 3:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2020, 3:56 PM

This makes sense. However, this is not NFC. Do you have a test case?

Example:

define internal i32 @callee(i1 %C, i32* %A) {
entry:
  %A.0 = load i32, i32* null
  br i1 %C, label %T, label %F

T:
  ret i32 %A.0

F:
  ret i32 1
}

define i32 @foo() {
  %X = call i32 @callee(i1 false, i32* null)
  ret i32 %X
}

I'll come back tomorrow to add it as a test.

This makes sense. However, this is not NFC. Do you have a test case?

My bad, let me actually add the test case now.

baziotis updated this revision to Diff 248860.Mar 6 2020, 4:22 PM
baziotis retitled this revision from [Attributor][NFC] Fold terminators before changing instructions to unreachable to [Attributor] Fold terminators before changing instructions to unreachable.

Added test case.

This revision is now accepted and ready to land.Mar 6 2020, 9:57 PM
This revision was automatically updated to reflect the committed changes.