This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Support vectors in simplifyWithOpReplaced()
ClosedPublic

Authored by nikic on Sep 21 2022, 3:33 AM.

Details

Summary

We can handle vectors inside simplifyWithOpReplaced(), as long as cross-lane operations are excluded. The equality can hold (or not hold) for each vector lane independently, so we shouldn't use the replacement value from other lanes.

I believe the only operations relevant here are shufflevector (where all previous bugs were seen) and calls (which might use shuffle-like intrinsics and would require more careful classification).

Diff Detail

Event Timeline

nikic created this revision.Sep 21 2022, 3:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2022, 3:33 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.Sep 21 2022, 3:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2022, 3:33 AM

Seems right, but do we have tests that exercise the call restriction? Maybe something like these:

declare <2 x i32> @llvm.sadd.sat.v2i32(<2 x i32>, <2 x i32>)
declare <2 x i32> @arbitrary_call(<2 x i32>)

define <2 x i32> @could_fold(<2 x i32> %x, <2 x i32> %y) {
  %a = call <2 x i32> @llvm.sadd.sat.v2i32(<2 x i32> %x, <2 x i32> <i32 42, i32 42>)
  %cond = icmp eq <2 x i32> %x, zeroinitializer
  %s = select <2 x i1> %cond, <2 x i32> %a, <2 x i32> %y
  ret <2 x i32> %s
}

define <2 x i32> @must_not_fold(<2 x i32> %x, <2 x i32> %y) {
  %a = call <2 x i32> @arbitrary_call(<2 x i32> %x)
  %cond = icmp eq <2 x i32> %x, zeroinitializer
  %s = select <2 x i1> %cond, <2 x i32> %a, <2 x i32> %y
  ret <2 x i32> %s
}
nikic updated this revision to Diff 461897.Sep 21 2022, 8:06 AM

Rebase over additional tests with calls.

spatel accepted this revision.Sep 21 2022, 8:37 AM

LGTM

This revision is now accepted and ready to land.Sep 21 2022, 8:37 AM
This revision was landed with ongoing or failed builds.Sep 22 2022, 1:45 AM
This revision was automatically updated to reflect the committed changes.