This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Handle usubo always overflow
ClosedPublic

Authored by nikic on Apr 9 2019, 1:05 PM.

Details

Summary

Check AlwaysOverflow condition for usubo. The implementation is the same as the existing handling for uaddo and umulo. Handling for saddo and ssubo will follow (smulo doesn't have the necessary ValueTracking support).

Diff Detail

Repository
rL LLVM

Event Timeline

nikic created this revision.Apr 9 2019, 1:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2019, 1:05 PM
lebedev.ri accepted this revision.Apr 9 2019, 3:19 PM

Looks good, consider landing as two commits.

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
3940 ↗(On Diff #194384)

Hm, i should check if this can be used (or is already used?) for some of the implicit-conversion checks that aren't using overflow intrinsics, but plain ir..

3993 ↗(On Diff #194384)

And willNotOverflowUnsignedSub() is: (unless i'm looking at the wrong func?)

bool willNotOverflowUnsignedSub(const Value *LHS, const Value *RHS,
                                const Instruction &CxtI) const {
  return computeOverflowForUnsignedSub(LHS, RHS, &CxtI) ==
         OverflowResult::NeverOverflows;
}

So this should ideally be:
patch 0 (nfc)

- if (willNotOverflowUnsignedSub(LHS, RHS, OrigI))
+ OverflowResult OR = computeOverflowForUnsignedSub(LHS, RHS, &OrigI);
+ if (OR == OverflowResult::NeverOverflows)

patch 1 -

+ if (OR == OverflowResult::AlwaysOverflows)
+   return SetResult(Builder.CreateSub(LHS, RHS), Builder.getTrue(), true);
This revision is now accepted and ready to land.Apr 9 2019, 3:19 PM
This revision was automatically updated to reflect the committed changes.
nikic marked 2 inline comments as done.Apr 10 2019, 12:11 AM
nikic added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
3940 ↗(On Diff #194384)

Apart from with.overflow handling this function is used in one more place: https://github.com/llvm-mirror/llvm/blob/29ea2070bd62816674f48ac392a1ee24e5c915cf/lib/Transforms/InstCombine/InstCombineCompares.cpp#L5049-L5060 Not sure if that's the usage you have in mind.

3993 ↗(On Diff #194384)

I've split out the willNot -> computeOverflow change (for all cases) into rL358051.