This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Handle vector compares in foldGEPIcmp(), take 2
ClosedPublic

Authored by JesperAntonsson on Sep 25 2018, 7:24 AM.

Details

Summary

This is a continuation of the fix for PR34627 "InstCombine assertion at vector gep/icmp folding". (I just realized bugpoint had fuzzed the original test for me, so I had fixed another trigger of the same assert in adjacent code in InstCombine.)

This patch avoids optimizing an icmp (to look only at the base pointers) when the resulting icmp would have a different type.

The patch adds a testcase and also cleans up and shrinks the pre-existing test for the adjacent assert trigger.

Diff Detail

Event Timeline

lebedev.ri added inline comments.Sep 26 2018, 12:33 PM
lib/Transforms/InstCombine/InstCombineCompares.cpp
911

I don't know it, but wouldn't it be possible to compare the types themselves directly?
How does icmp ensure that the types are compatible?

lib/Transforms/InstCombine/InstCombineCompares.cpp
911

With this patch, I'm trying to ensure the new and old ICmps have the same types, so that we can safely do replaceAllUsesWith(). That the two operands to the new ICmp have the same types is ensured already.

I can compare the ICmp types directly, but then I first have to create the new ICmp. What I do now is look at one operand of the new ICmp to check if it will get the same type as the old ICmp. E.g. if the old ICmp is {4 x i1] and the new operand is [4 x i16] then the new ICmp will have the same type as the old.

Perhaps it'd be cleaner to create the ICmp and then delete it and move on if it doesn't have the same type? I'll prepare and upload a patch with that for comparison.

This patch checks icmp types directly. This might be simpler than checking the operand type.

spatel added inline comments.Sep 27 2018, 11:16 AM
lib/Transforms/InstCombine/InstCombineCompares.cpp
911

I think the API you're looking for is:
CmpInst::makeCmpResultType()

Creating and deleting an object is likely much more expensive than doing a type check.

Thanks, Sanjay. Using makeCmpResultType() in this patch for a smaller and nicer diff.

lebedev.ri accepted this revision.Oct 1 2018, 5:55 AM

Thanks, that is indeed what i expected to see.
One nit, but i'm really unsure of it.

lib/Transforms/InstCombine/InstCombineCompares.cpp
911–912

I'm not sure this helper variable is/isn't any better than without it?

This revision is now accepted and ready to land.Oct 1 2018, 5:55 AM

Thanks.

lib/Transforms/InstCombine/InstCombineCompares.cpp
911–912

I tried without and really felt the expression became too complex and unwieldy.

This revision was automatically updated to reflect the committed changes.