This is an archive of the discontinued LLVM Phabricator instance.

[CVP] Don't introduce zero after truncating when narrowUDivOrSDiv
Needs ReviewPublic

Authored by StephenFan on May 11 2023, 3:29 AM.

Details

Summary

The constant range computed at use point does not mean the input
constant range or in other words, the constant range computed at define point,
is the same range as computed at use point. For intructions that is
always speculative, it is safe. However, for instruction UDiv or SDiv,
and we want to narrow the data type of these, zero may be introduced
after truncating the divisor and causing an UB.

So this patch checks that if the constant range at define point does not
contain zero, then it also must not contain zero after truncating.

Diff Detail

Event Timeline

StephenFan created this revision.May 11 2023, 3:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2023, 3:29 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
StephenFan requested review of this revision.May 11 2023, 3:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2023, 3:29 AM

Delete blank line

goldstein.w.n added inline comments.May 11 2023, 7:49 AM
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
813

narrowSDivOrSRem i think