This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] check vector elements before trying to transform LE/GE vector icmp (PR27756)
ClosedPublic

Authored by spatel on May 16 2016, 10:07 AM.

Details

Summary

Fix a bug introduced with rL269426 :
[InstCombine] canonicalize* LE/GE vector integer comparisons to LT/GT (PR26701, PR26819)

We were assuming that a ConstantDataVector / ConstantVector / ConstantAggregateZero operand of an ICMP was composed of ConstantInt elements, but it might have ConstantExpr or UndefValue elements. Handle those appropriately.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 57363.May 16 2016, 10:07 AM
spatel retitled this revision from to [InstCombine] check vector elements before trying to transform LE/GE vector icmp (PR27756).
spatel updated this object.
spatel added reviewers: jmolloy, majnemer, chandlerc.
spatel added a subscriber: llvm-commits.
majnemer added inline comments.May 16 2016, 10:16 AM
lib/Transforms/InstCombine/InstCombineCompares.cpp
3134–3135 ↗(On Diff #57363)

Can we just make this Op1->getType()->isVectorTy() ?

spatel added inline comments.May 16 2016, 10:24 AM
lib/Transforms/InstCombine/InstCombineCompares.cpp
3134–3135 ↗(On Diff #57363)

We still need to make sure Op1 is a Constant, but yes, I think that will be cleaner.

spatel updated this revision to Diff 57372.May 16 2016, 10:55 AM

Patch updated:
Simplify check for transform to use operand type (we just need a vector constant of some kind).

chandlerc added inline comments.May 16 2016, 11:04 AM
lib/Transforms/InstCombine/InstCombineCompares.cpp
3138–3140 ↗(On Diff #57372)

Instead of the bool flags here, I would pass in the predicate value and handle that internally.

With that, I tihnk you can completely eliminate the switch in the calling code as the only other difference is 1 vs. -1.

majnemer added inline comments.May 16 2016, 11:06 AM
lib/Transforms/InstCombine/InstCombineCompares.cpp
3165–3185 ↗(On Diff #57372)

I'd recommend passing I.isSigned() in instead of hard-coding true/false. Makes it harder to make a mistake when updating this switch/case.

spatel added inline comments.May 16 2016, 2:29 PM
lib/Transforms/InstCombine/InstCombineCompares.cpp
3138–3140 ↗(On Diff #57372)

We still have to choose 1 of the 4 predicate values, but I'll take the anti-switch bait. :)
Lets try for max density via ?: and see if that reads better.

spatel updated this revision to Diff 57405.May 16 2016, 2:51 PM

Patch updated:

  1. Refactored to use the same main logic path for scalar/vector.
  2. Replace switches with ?: ops.
  3. Eliminate lambda.
  4. Remove unused Builder param.
chandlerc accepted this revision.May 16 2016, 5:05 PM
chandlerc edited edge metadata.

LGTM. I think this could be cleaned up some more, but I think its fine for you to land as-is -- it'll be easier to just clean up the formatting after-the-fact.

This revision is now accepted and ready to land.May 16 2016, 5:05 PM
This revision was automatically updated to reflect the committed changes.