This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fix constexpr issue in select combining
ClosedPublic

Authored by RKSimon on Oct 11 2016, 4:18 AM.

Details

Summary

As discussed by Andrea on PR30486, we have an unsafe cast to an Instruction type in the select combine which doesn't take into account that it could be a ConstantExpr instead.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon updated this revision to Diff 74230.Oct 11 2016, 4:18 AM
RKSimon retitled this revision from to [InstCombine] Fix constexpr issue in select combining.
RKSimon updated this object.
RKSimon added reviewers: majnemer, bogner, andreadb, spatel.
RKSimon set the repository for this revision to rL LLVM.
RKSimon added a subscriber: llvm-commits.
andreadb accepted this revision.Oct 11 2016, 4:45 AM
andreadb edited edge metadata.

Hi Simon,

the patch looks good to me.
I suggest to improve the test case by adding multiple cases to the switch statement. That would prove that the optimization still works okay even with constant expressions (see below).

Example:

@g = global i32 0

define i32 @func() {
  switch i32 add (i32 ptrtoint (i32* @g to i32), i32 -1), label %x [
    i32 1, label %one
    i32 2, label %two
  ]
x:
  ret i32 0

one:
  ret i32 1

two:
  ret i32 2
}

The above case should be combined to this:

define i32 @func() {
  switch i32 ptrtoint (i32* @g to i32), label %x [
    i32 2, label %one
    i32 3, label %two
  ]

x:                                                ; preds = %0
  ret i32 0

one:                                              ; preds = %0
  ret i32 1

two:                                              ; preds = %0
  ret i32 2

Thanks!
Andrea

This revision is now accepted and ready to land.Oct 11 2016, 4:45 AM
RKSimon closed this revision.Oct 12 2016, 3:56 AM

Fixed in rL284000 - I added Andrea's alternate test case so we test both single case and multiple case switches.