This is an archive of the discontinued LLVM Phabricator instance.

stop llvm-reduce's ReduceBasicBlocks delta pass from creating invalid IR
ClosedPublic

Authored by regehr on Aug 2 2022, 3:18 PM.

Details

Summary

When the basic block delta pass removes the first basic block in a function, that function becomes illegal if the second block has extra predecessors. The function below is an example of one that triggers this issue. While we could think of various clever ways to fix this issue, the patch here simply makes the entry block ineligible for removal.

define void @aeDeleteEventLoop(ptr %0) {

%2 = alloca ptr, i32 0, align 8
%3 = alloca ptr, i32 0, align 8
call void @zfree()
br label %4

4: ; preds = %6, %1

%5 = icmp ne ptr %0, null
br i1 %5, label %6, label %7

6: ; preds = %4

store ptr null, ptr null, align 8
br label %4

7: ; preds = %4

ret void

}

Diff Detail

Event Timeline

regehr created this revision.Aug 2 2022, 3:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2022, 3:18 PM
regehr requested review of this revision.Aug 2 2022, 3:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2022, 3:18 PM

could you add a test case that uses -abort-on-invalid-reduction?

regehr updated this revision to Diff 449513.Aug 2 2022, 7:24 PM

thanks Arthur-- I've added this test and also refined the safety check in the pass to be less conservative

arsenm accepted this revision.Aug 2 2022, 7:41 PM
arsenm added a subscriber: arsenm.

LGTM. I do think something is off about how the pass currently tries to auto-fold unconditional branches to successors. I was thinking there should be a separate control flow simplification to clean those up

llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
105

Capitalize a

This revision is now accepted and ready to land.Aug 2 2022, 7:41 PM
aeubanks accepted this revision.Aug 2 2022, 7:48 PM
regehr added a comment.EditedAug 2 2022, 9:05 PM

LGTM. I do think something is off about how the pass currently tries to auto-fold unconditional branches to successors. I was thinking there should be a separate control flow simplification to clean those up

hey I have written this and am just testing and cleaning it up!! hope to submit the patch for review soonish, I will tag you in it :)