[PATCH] D155726: [InstCombine] Test case for D155718+D154064

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 00:48:07 PDT 2023


nikic added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/icmp-fold-into-phi.ll:97
+declare zeroext i1 @StrCmp(ptr noundef, ptr noundef)
+declare zeroext i1 @CheckCond()
----------------
0xdc03 wrote:
> nikic wrote:
> > nikic wrote:
> > > 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.
> > 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
> > ```
> 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:
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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155726/new/

https://reviews.llvm.org/D155726



More information about the llvm-commits mailing list