[InstCombine] fix bug when offsetting case values of a switch (PR31260)
authorSanjay Patel <spatel@rotateright.com>
Mon, 12 Dec 2016 16:13:52 +0000 (16:13 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 12 Dec 2016 16:13:52 +0000 (16:13 +0000)
commite730ce87a50c1fbfc1a6a0828e472b0b2f67beab
tree4dfe3733aef71cb7b8d95cb494855856d1d66e73
parent040cc168355ab839053710f35fb039b4391ec5ec
[InstCombine] fix bug when offsetting case values of a switch (PR31260)

We could truncate the condition and then try to fold the add into the
original condition value causing wrong case constants to be used.

Move the offset transform ahead of the truncate transform and return
after each transform, so there's no chance of getting confused values.

Fix for:
https://llvm.org/bugs/show_bug.cgi?id=31260

llvm-svn: 289442
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/narrow-switch.ll