summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
diff options
context:
space:
mode:
authorAmara Emerson <aemerson@apple.com>2018-10-25 14:04:54 +0000
committerAmara Emerson <aemerson@apple.com>2018-10-25 14:04:54 +0000
commitcbd86d842902da3581926ee4cd2d207b9d2d1e53 (patch)
tree2c1ecf5b23708553a5d9f9eda803fc8fca97369d /llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
parent142919bc23f1abf986fc061947f45120af63396d (diff)
downloadbcm5719-llvm-cbd86d842902da3581926ee4cd2d207b9d2d1e53.tar.gz
bcm5719-llvm-cbd86d842902da3581926ee4cd2d207b9d2d1e53.zip
[GlobalISel] Use the target preferred type for G_EXTRACT_VECTOR_ELT index.
Allows for better imported pattern re-use. llvm-svn: 345265
Diffstat (limited to 'llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp')
-rw-r--r--llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 709965ba151..ab7d3a87975 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -1330,7 +1330,22 @@ bool IRTranslator::translateExtractElement(const User &U,
}
unsigned Res = getOrCreateVReg(U);
unsigned Val = getOrCreateVReg(*U.getOperand(0));
- unsigned Idx = getOrCreateVReg(*U.getOperand(1));
+ const auto &TLI = *MF->getSubtarget().getTargetLowering();
+ unsigned PreferredVecIdxWidth = TLI.getVectorIdxTy(*DL).getSizeInBits();
+ unsigned Idx = 0;
+ if (auto *CI = dyn_cast<ConstantInt>(U.getOperand(1))) {
+ if (CI->getBitWidth() != PreferredVecIdxWidth) {
+ APInt NewIdx = CI->getValue().sextOrTrunc(PreferredVecIdxWidth);
+ auto *NewIdxCI = ConstantInt::get(CI->getContext(), NewIdx);
+ Idx = getOrCreateVReg(*NewIdxCI);
+ }
+ }
+ if (!Idx)
+ Idx = getOrCreateVReg(*U.getOperand(1));
+ if (MRI->getType(Idx).getSizeInBits() != PreferredVecIdxWidth) {
+ const LLT &VecIdxTy = LLT::scalar(PreferredVecIdxWidth);
+ Idx = MIRBuilder.buildSExtOrTrunc(VecIdxTy, Idx)->getOperand(0).getReg();
+ }
MIRBuilder.buildExtractVectorElement(Res, Val, Idx);
return true;
}
OpenPOWER on IntegriCloud