This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Take arguments into consideration when simplify range check
AbandonedPublic

Authored by guopeilin on Nov 2 2021, 9:03 PM.

Diff Detail

Event Timeline

guopeilin created this revision.Nov 2 2021, 9:03 PM
guopeilin requested review of this revision.Nov 2 2021, 9:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2021, 9:03 PM
lebedev.ri requested changes to this revision.Nov 3 2021, 12:28 AM
lebedev.ri added a subscriber: lebedev.ri.

Patch missing description.
I do not understand what this does, but i really strongly suspect you are trying to hide an UB in the original IR.

llvm/test/Transforms/InstCombine/range-check.ll
1

Why was this deleted?

This revision now requires changes to proceed.Nov 3 2021, 12:28 AM
lebedev.ri added inline comments.Nov 3 2021, 12:30 AM
llvm/test/Transforms/InstCombine/simplify-range-check.ll
5

The current result is not a miscompile: https://alive2.llvm.org/ce/z/bZAccs

Sorry for the absence of the description.
Actually, it is a runtime error. The simplify range check optimization will change (icmp slt x, 0) | (icmp sgt x, n) into icmp ugt x, n
Now, suppose the %0 is negative, Before optimizing, we will compare the argument with 0 to see whether the argument is less than 0, if so, we will finally return shl i32 %0, 0.
However, after optimizing, we will not have this comparison, and we will finally return shl i32 %0, %and. The problem is that %and is also driven from the argument, it can be undefined cause it is a shift operation that depends on the argument. So, after optimization, we will get an undefined result.
So, I guess that if both x and n in (icmp slt x, 0) | (icmp sgt x, n) are derived from the argument, then we should be conservative.

guopeilin updated this revision to Diff 384939.Nov 4 2021, 6:47 PM
guopeilin added inline comments.
llvm/test/Transforms/InstCombine/range-check.ll
1

all the variable optimized in the functions within this file are derived from arguments, so the IR won't get changed after this patch.

lebedev.ri requested changes to this revision.Nov 5 2021, 12:24 AM
This revision now requires changes to proceed.Nov 5 2021, 12:24 AM
guopeilin abandoned this revision.Dec 10 2021, 10:32 PM