This is an archive of the discontinued LLVM Phabricator instance.

[Transforms] Enhance CorrelatedValuePropagation to handle both values of select
ClosedPublic

Authored by slydiman on Feb 12 2022, 11:30 AM.

Details

Summary

The "Correlated Value Propagation" pass was missing a case when handling select instructions. It was only handling the "false" constant value, while in NVPTX the select may have the condition (and thus the branches) inverted, for example:

loop:
	%phi = phi i32* [ %sel, %loop ], [ %x, %entry ]
	%f = tail call i32* @f(i32* %phi)
	%cmp1 = icmp ne i32* %f, %y
	%sel = select i1 %cmp1, i32* %f, i32* null
	%cmp2 = icmp eq i32* %sel, null
	br i1 %cmp2, label %return, label %loop

But the select condition can be inverted:

	%cmp1 = icmp eq i32* %f, %y
	%sel = select i1 %cmp1, i32* null, i32* %f

The fix is to enhance "Correlated Value Propagation" to handle both branches of the select instruction.

Diff Detail

Event Timeline

slydiman created this revision.Feb 12 2022, 11:30 AM
slydiman requested review of this revision.Feb 12 2022, 11:30 AM
slydiman updated this revision to Diff 408266.Feb 13 2022, 8:17 AM
nikic added a comment.Feb 14 2022, 2:01 AM

This looks reasonable, as we do not generally canonicalize constants in select to the RHS. It looks like your new test is based on @test5() from basic.ll, can you please add the new one next to it, precommit and rebase?

slydiman updated this revision to Diff 408410.Feb 14 2022, 7:22 AM

It looks like your new test is based on @test5() from basic.ll, can you please add the new one next to it, precommit and rebase?

Done

lebedev.ri accepted this revision.Feb 20 2022, 10:12 AM
lebedev.ri added a subscriber: lebedev.ri.

Please precommit the tests first.
LGTM

This revision is now accepted and ready to land.Feb 20 2022, 10:12 AM

Please precommit the tests first.

Thanks for the review. Could you provide some details how to precommit these tests? This patch contains 2 new tests inside the existing file basic.ll. @loop1 will be green anyway, but @loop2 will be red w/o this patch. I don't see a way to apply XFAIL to @loop2.

Could you provide some details how to precommit these tests?

Never mind. I have figured that out.