Page MenuHomePhabricator

[InstCombine] (a+b) <= a && (a+b) != 0 -> (0-b) < a (PR43259)
ClosedPublic

Authored by lebedev.ri on Sep 20 2019, 10:57 AM.

Details

Summary

This is again motivated by D67122 sanitizer check enhancement.
That patch seemingly worsens -fsanitize=pointer-overflow
overhead from 25% to 50%, which strongly implies missing folds.

This pattern isn't exactly what we get there
(strict vs. non-strict predicate), but this pattern does not
require known-bits analysis, so it is best to handle it first.

Name: 0
  %adjusted = add i8 %base, %offset
  %not_null = icmp ne i8 %adjusted, 0
  %no_underflow = icmp ule i8 %adjusted, %base
  %r = and i1 %not_null, %no_underflow
=>
  %neg_offset = sub i8 0, %offset
  %r = icmp ugt i8 %base, %neg_offset

https://rise4fun.com/Alive/knp

There are 3 other variants of this pattern,
they all will go into InstSimplify:
https://rise4fun.com/Alive/bIDZ

https://bugs.llvm.org/show_bug.cgi?id=43259

Diff Detail

Repository
rL LLVM

Event Timeline

lebedev.ri created this revision.Sep 20 2019, 10:57 AM
spatel added inline comments.Sep 23 2019, 8:34 AM
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
1068 ↗(On Diff #221067)

It's confusing to call this "Subtracted" when we're matching an add. Rename to something more generic like "ZeroCmpOp"?

lebedev.ri marked 2 inline comments as done.

Rebased after changing variable name.

spatel accepted this revision.Sep 23 2019, 9:17 AM

LGTM

This revision is now accepted and ready to land.Sep 23 2019, 9:17 AM
lebedev.ri added inline comments.Sep 23 2019, 9:34 AM
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
1068 ↗(On Diff #221067)

Yeah, that was an unfortunate name choice in retrospect..

LGTM

Thank you for the review!
There's also D67849.

In principle, that is all to fix PR43259, which as far as i'm currently aware
is the last instcombine/instsimplify part of sanitizer patch (D67122).
Though i should follow-up with a last patch to handle instsimplify patterns.

Rebased, NFC.

This revision was automatically updated to reflect the committed changes.