diff options
| author | Craig Topper <craig.topper@intel.com> | 2019-11-06 12:39:09 -0800 |
|---|---|---|
| committer | Craig Topper <craig.topper@intel.com> | 2019-11-06 13:03:18 -0800 |
| commit | 641d2e5232b423a7dd81afac94dd3db4412a4971 (patch) | |
| tree | 774d8910b41ce6079f99210dda0418d314f0e337 /llvm/lib | |
| parent | 35cf9a1fc5d2ab7c171c968737092874676ce8ea (diff) | |
| download | bcm5719-llvm-641d2e5232b423a7dd81afac94dd3db4412a4971.tar.gz bcm5719-llvm-641d2e5232b423a7dd81afac94dd3db4412a4971.zip | |
[X86] Clamp large constant shift amounts for MMX shift intrinsics to 8-bits.
The MMX intrinsics for shift by immediate take a 32-bit shift
amount but the hardware for shifting by immediate only encodes
8-bits. For the intrinsic we don't require the shift amount to
fit in 8-bits in the frontend because we don't check that its an
immediate in the frontend. If its is not an immediate we move it
to an MMX register and use the shift by register.
But if it is an immediate we'll use the shift by immediate
instruction. But we need to change the shift amount to 8-bits.
We were previously doing this accidentally by masking it in the
encoder. But this can make a large shift amount into a small
in bounds shift amount. Instead we should clamp larger shift
amounts to 255 so that the they don't become in bounds.
Fixes PR43922
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/X86/X86ISelLowering.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index bb975e59ccf..e9c32c1f336 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -23636,9 +23636,12 @@ SDValue X86TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SDValue ShAmt = Op.getOperand(2); // If the argument is a constant, convert it to a target constant. if (auto *C = dyn_cast<ConstantSDNode>(ShAmt)) { - ShAmt = DAG.getTargetConstant(C->getZExtValue(), DL, MVT::i32); + // Clamp out of bounds shift amounts since they will otherwise be masked + // to 8-bits which may make it no longer out of bounds. + unsigned ShiftAmount = C->getAPIntValue().getLimitedValue(255); return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, Op.getValueType(), - Op.getOperand(0), Op.getOperand(1), ShAmt); + Op.getOperand(0), Op.getOperand(1), + DAG.getTargetConstant(ShiftAmount, DL, MVT::i32)); } unsigned NewIntrinsic; |

