This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Test case for D155718
ClosedPublic

Authored by 0xdc03 on Jul 19 2023, 10:20 AM.

Diff Detail

Event Timeline

0xdc03 created this revision.Jul 19 2023, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 10:20 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
0xdc03 requested review of this revision.Jul 19 2023, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 10:20 AM
nikic added inline comments.Jul 19 2023, 12:18 PM
llvm/test/Transforms/InstCombine/icmp-fold-into-phi.ll
98

This test looks too complicated for what we actually want to test. I think something like this should be sufficient:

define i1 @test(i32 %x, i32 %y) {
entry:
  switch i32 %x, label %bb1 [
    i32 0, label %bb2
    i32 1, label %bb3
  ]

bb1:
  br label %bb2

bb2:
  %phi1 = phi i32 [ 1, %entry ], [ %y, %bb1 ]
  br label %bb3

bb3:
  %phi2 = phi i32 [ %phi1, %bb2 ], [ 0, %entry ]
  %cmp = icmp ugt i32 %phi2, 1
  ret i1 %cmp
}

This would also make it independent of D154064 and allow us to land this patch first.

nikic added inline comments.Jul 19 2023, 12:24 PM
llvm/test/Transforms/InstCombine/icmp-fold-into-phi.ll
98

Well, I guess it would make sense to also add your test to make sure that D154064 doesn't regress it, but in that case we should cut it down a bit. There's a lot of parts that aren't really relevant, e.g. the final block could be just this I think:

%cond3       = phi i32 [ %cond2, %sw.bb ], [ 134, %cond.false2 ], [ 2, %cond.false ], [ 1, %entry ]
%cmp         = icmp ult i32 %cond3, 2
ret i1 %cmp
0xdc03 updated this revision to Diff 542296.Jul 19 2023, 9:24 PM
  • Add simple test
  • Add simplified test
0xdc03 marked an inline comment as done.Jul 19 2023, 9:26 PM
0xdc03 added inline comments.
llvm/test/Transforms/InstCombine/icmp-fold-into-phi.ll
98

Hmm, I have added another version of this test which is simplified - I still feel that the original test highlights the fold more clearly :shrug:

nikic added inline comments.Jul 20 2023, 12:48 AM
llvm/test/Transforms/InstCombine/icmp-fold-into-phi.ll
98

Here is a simplified version of the original test:

define i1 @test(i1 %c, i1 %c1, i1 %c2, i1 %c3, i1 %c4) {
entry:
  br i1 %c, label %sw.epilog, label %cond.false

cond.false:
  br i1 %c1, label %sw.epilog, label %cond.false2

cond.false2:
  br i1 %c2, label %sw.epilog, label %cond.false3

cond.false3:
  br i1 %c3, label %sw.bb, label %cond.end

cond.end:
  %cond = select i1 %c4, i32 127, i32 126
  br label %sw.bb

sw.bb:
  %cond2 = phi i32 [ %cond, %cond.end ], [ 128, %cond.false3 ]
  br label %sw.epilog

sw.epilog:
  %cond3 = phi i32 [ %cond2, %sw.bb ], [ 134, %cond.false2 ], [ 2, %cond.false ], [ 1, %entry ]
  %cmp  = icmp ult i32 %cond3, 2
  ret i1 %cmp
}

This just has the phi nodes and icmp necessary to perform the fold and omits all the function calls (and globals, and declarations needed for them).

We're not aiming for realism here, but for something minimal that shows the change in behavior.

0xdc03 updated this revision to Diff 542365.Jul 20 2023, 1:24 AM
  • Address reviewer comments
    • Better test
  • Invert the patch stack
0xdc03 marked 2 inline comments as done.Jul 20 2023, 1:27 AM
0xdc03 edited the summary of this revision. (Show Details)Jul 20 2023, 1:29 AM
nikic accepted this revision.Jul 20 2023, 1:35 AM

LGTM

This revision is now accepted and ready to land.Jul 20 2023, 1:35 AM
0xdc03 updated this revision to Diff 542374.Jul 20 2023, 1:49 AM
  • Change the patch order
0xdc03 updated this revision to Diff 550710.Aug 16 2023, 5:51 AM
  • Rebase on main
0xdc03 retitled this revision from [InstCombine] Test case for D155718+D154064 to [InstCombine] Test case for D155718.Aug 16 2023, 5:53 AM
0xdc03 edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Aug 16 2023, 8:40 AM
This revision was automatically updated to reflect the committed changes.