[llvm-commits] [llvm] r164926 - /llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp

Hans Wennborg hans at chromium.org
Mon Oct 1 09:36:54 PDT 2012


On Mon, Oct 1, 2012 at 8:50 AM, Craig Topper <craig.topper at gmail.com> wrote:
> It was forming a jump table instead of just a constant lookup table because
> of the subtract in there making it so that not everything was a constant.
> Maybe there should be some way to detect that the subtract was only
> dependent on the switch value?

I've added this to my list of things to look at. I think it will be a
nice enhancement.

I figure we just need to propagate the constant value of the condition
expression through the block and see if a constant comes out at the
end.


I will also look at using a more narrow type for the tables (i.e. if
all values fit in three bits, just use i3). I was planning to do this
mostly for the case where the whole table fits in a register, but I
guess it makes sense for the arrays too.

It's not entirely obvious when to do this, though. If all results are
i32, but fit in i8, it's obvious. But if all results are i8, but fit
in i7? Packing the values will make extracting them slower, so it's
not given that we always want to use the smallest possible type.

Thanks,
Hans


> On Mon, Oct 1, 2012 at 12:40 AM, Chandler Carruth <chandlerc at google.com>
> wrote:
>>
>> On Mon, Oct 1, 2012 at 12:33 AM, Craig Topper <craig.topper at gmail.com>
>> wrote:
>>>
>>> Author: ctopper
>>> Date: Mon Oct  1 02:33:27 2012
>>> New Revision: 164926
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=164926&view=rev
>>> Log:
>>> Use constants for all return values in switch. Allows clang to optimize
>>> it into a lookup table.
>>>
>>> Modified:
>>>     llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
>>>
>>> Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp?rev=164926&r1=164925&r2=164926&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp (original)
>>> +++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp Mon Oct  1
>>> 02:33:27 2012
>>> @@ -243,9 +243,14 @@
>>>    case X86::R15: case X86::R15D: case X86::R15W: case X86::R15B:
>>>      return N86::EDI;
>>>
>>> -  case X86::ST0: case X86::ST1: case X86::ST2: case X86::ST3:
>>> -  case X86::ST4: case X86::ST5: case X86::ST6: case X86::ST7:
>>> -    return RegNo-X86::ST0;
>>> +  case X86::ST0: return 0;
>>> +  case X86::ST1: return 1;
>>> +  case X86::ST2: return 2;
>>> +  case X86::ST3: return 3;
>>> +  case X86::ST4: return 4;
>>> +  case X86::ST5: return 5;
>>> +  case X86::ST6: return 6;
>>> +  case X86::ST7: return 7;
>>
>>
>> Out of curiosity, why are we unable to form the lookup table out of this?
>> It seems like a common pattern that should be directly supported.



More information about the llvm-commits mailing list