diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-06-30 14:51:21 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-06-30 14:51:21 +0000 |
commit | 7c6eab5777438c1ed75a2ce61dcfb9ec2edcd661 (patch) | |
tree | c274800ad6a3ee8375e89378b257f72ba3930076 /llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | |
parent | bda4cb6091413373113b9718044ffefe1fde7553 (diff) | |
download | llvm-7c6eab5777438c1ed75a2ce61dcfb9ec2edcd661.zip llvm-7c6eab5777438c1ed75a2ce61dcfb9ec2edcd661.tar.gz llvm-7c6eab5777438c1ed75a2ce61dcfb9ec2edcd661.tar.bz2 |
[InstCombine] shrink switch conditions better (PR24766)
https://llvm.org/bugs/show_bug.cgi?id=24766#c2
This removes a hack that was added for the benefit of x86 codegen.
It prevented shrinking the switch condition even to smaller legal (DataLayout) types.
We have a safety mechanism in CGP after:
http://reviews.llvm.org/rL251857
...so we're free to use the optimal (smallest) IR type now.
Differential Revision: http://reviews.llvm.org/D12965
llvm-svn: 274233
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index c25199d..c0fb365 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2185,17 +2185,15 @@ Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) { unsigned NewWidth = BitWidth - std::max(LeadingKnownZeros, LeadingKnownOnes); - // Truncate the condition operand if the new type is equal to or larger than - // the largest legal integer type. We need to be conservative here since - // x86 generates redundant zero-extension instructions if the operand is - // truncated to i8 or i16. + // Shrink the condition operand if the new type is smaller than the old type. + // This may produce a non-standard type for the switch, but that's ok because + // the backend should extend back to a legal type for the target. bool TruncCond = false; - if (NewWidth > 0 && BitWidth > NewWidth && - NewWidth >= DL.getLargestLegalIntTypeSizeInBits()) { + if (NewWidth > 0 && NewWidth < BitWidth) { TruncCond = true; IntegerType *Ty = IntegerType::get(SI.getContext(), NewWidth); Builder->SetInsertPoint(&SI); - Value *NewCond = Builder->CreateTrunc(SI.getCondition(), Ty, "trunc"); + Value *NewCond = Builder->CreateTrunc(Cond, Ty, "trunc"); SI.setCondition(NewCond); for (auto &C : SI.cases()) |