This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add test cases from PR62898. NFC.
ClosedPublic

Authored by dtcxzyw on Jul 25 2023, 4:04 AM.

Details

Summary

This patch adds some test cases from https://github.com/llvm/llvm-project/issues/62898.

As nikic noted in the issue, we should start by implementing a generalization of the fold smin(X, Y) < Z -> X < Z when Y > Z is implied by constant folds/invariants/dom conditions.

define i1 @src(i32 %x, i32 %y, i32 %z) {
  %cmp = icmp sgt i32 %y, %z
  br i1 %cmp, label %if, label %end
if:
  %cond = call i32 @llvm.smin.i32(i32 %x, i32 %y)
  %tobool = icmp slt i32 %cond, %z
  ret i1 %tobool
end:
  ret i1 false
}

define i1 @tgt(i32 %x, i32 %y, i32 %z) {
  %cmp = icmp sgt i32 %y, %z
  br i1 %cmp, label %if, label %end
if:
  %tobool = icmp slt i32 %x, %z
  ret i1 %tobool
end:
  ret i1 false
}

declare i32 @llvm.smin.i32(i32, i32)

Alive2: https://alive2.llvm.org/ce/z/dK9vXz

This patch also adds some generalized test cases like the above.

Diff Detail

Event Timeline

dtcxzyw created this revision.Jul 25 2023, 4:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 4:04 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
dtcxzyw requested review of this revision.Jul 25 2023, 4:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 4:04 AM
goldstein.w.n added inline comments.
llvm/test/Transforms/InstCombine/umin-icmp.ll
532

For the tests can you swap up %x and %y in some of the tests. Think you always do min/max(i32 %x, i32 %y) and always use %x, %z for the cond.

dtcxzyw updated this revision to Diff 554253.Aug 29 2023, 4:21 AM

Add commuted tests

dtcxzyw marked an inline comment as done.Aug 29 2023, 4:50 AM
dtcxzyw updated this revision to Diff 556340.Sep 9 2023, 12:23 AM

Add vector tests

This revision is now accepted and ready to land.Sep 10 2023, 10:54 AM
This revision was automatically updated to reflect the committed changes.