This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Make foldSelectOpOp able to handle two-operand getelementptr
ClosedPublic

Authored by john.brawn on Nov 13 2017, 8:17 AM.

Details

Summary

Three (or more) operand getelementptrs could plausibly also be handled, but handling only two-operand fits in easily with the existing BinaryOperator handling.

Diff Detail

Repository
rL LLVM

Event Timeline

john.brawn created this revision.Nov 13 2017, 8:17 AM
majnemer added inline comments.
lib/Transforms/InstCombine/InstCombineSelect.cpp
346–348

Please consistently brace.

347–348
351–353

Is this clang-format'd?

354–355

Brace this too.

Adjusted braces and clang-formatted.

majnemer added inline comments.Nov 14 2017, 8:41 PM
lib/Transforms/InstCombine/InstCombineSelect.cpp
346–356

auto *BO

349

I think this dyn_cast can just be cast<>, then you can avoid the llvm_unreachable.

350

You dyn_cast but unconditionally deference. Should this be cast<> ?

john.brawn updated this revision to Diff 125314.Dec 4 2017, 5:35 AM

Update based on comments:

  • Use auto when RHS is a cast
  • Use cast instead of dyn_cast once we know we're dealing with GetElementPtrInst.
john.brawn added inline comments.Dec 4 2017, 5:41 AM
lib/Transforms/InstCombine/InstCombineSelect.cpp
349

I could do that, but that would make GetElementPtrInst be in essence the default case which doesn't really make sense, especially if we end up supporting other instructions here as well.

I added the tests with current output in rL322733. Can you rebase here so we just see the diffs (please use the script at utils/update_test_checks.py to regenerate the check lines)? I think we'll be good then.

Rebased patch.

spatel accepted this revision.Jan 18 2018, 10:31 AM

LGTM.

This revision is now accepted and ready to land.Jan 18 2018, 10:31 AM
This revision was automatically updated to reflect the committed changes.