This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Canonicalize comparisons between non-negative values and indvars
ClosedPublic

Authored by mkazantsev on Jul 4 2017, 5:54 AM.

Details

Summary

If there is a IndVar which is known to be non-negative, and there is a value which is also non-negative,
then signed and unsigned comparisons between them produce the same result. Both of those can be
seen in the same loop. To allow other optimizations to simplify them, we turn all instructions like

%c = icmp slt i32 %iv, %b

to

%c = icmp ult i32 %iv, %b

if both %iv and %b are known to be non-negative.

Diff Detail

Repository
rL LLVM

Event Timeline

mkazantsev created this revision.Jul 4 2017, 5:54 AM
alexfh removed a reviewer: alexfh.Jul 4 2017, 7:06 AM
sanjoy accepted this revision.Jul 4 2017, 1:15 PM

lgtm

lib/Transforms/Utils/SimplifyIndVar.cpp
265 ↗(On Diff #105158)

I think writing the first part as ICmpInst::isSigned(Pred) would be clearer.

This revision is now accepted and ready to land.Jul 4 2017, 1:15 PM
skatkov accepted this revision.Jul 4 2017, 7:34 PM
mkazantsev marked an inline comment as done.
This revision was automatically updated to reflect the committed changes.

This patch was reverted due to the failure of the test SaturatingMultiply on stage 2 clang build. I'm pretty much convinced that this patch has exposed some buggy behavior within clang that made a bug in stage 2 clang, and that's how we got there. Need to figure out what are the steps to re-enable that.