|
8 | 8 |
|
9 | 9 | #include "DXILLegalizePass.h"
|
10 | 10 | #include "DirectX.h"
|
| 11 | +#include "llvm/ADT/APInt.h" |
| 12 | +#include "llvm/IR/Constants.h" |
11 | 13 | #include "llvm/IR/Function.h"
|
12 | 14 | #include "llvm/IR/IRBuilder.h"
|
13 | 15 | #include "llvm/IR/InstIterator.h"
|
@@ -317,6 +319,48 @@ static void removeMemSet(Instruction &I,
|
317 | 319 | ToRemove.push_back(CI);
|
318 | 320 | }
|
319 | 321 |
|
| 322 | +static void |
| 323 | +legalizeGetHighLowi64Bytes(Instruction &I, |
| 324 | + SmallVectorImpl<Instruction *> &ToRemove, |
| 325 | + DenseMap<Value *, Value *> &ReplacedValues) { |
| 326 | + if (auto *BitCast = dyn_cast<BitCastInst>(&I)) { |
| 327 | + if (BitCast->getDestTy() == |
| 328 | + FixedVectorType::get(Type::getInt32Ty(I.getContext()), 2) && |
| 329 | + BitCast->getSrcTy()->isIntegerTy(64)) { |
| 330 | + ToRemove.push_back(BitCast); |
| 331 | + ReplacedValues[BitCast] = BitCast->getOperand(0); |
| 332 | + } |
| 333 | + } |
| 334 | + |
| 335 | + if (auto *Extract = dyn_cast<ExtractElementInst>(&I)) { |
| 336 | + auto *VecTy = dyn_cast<FixedVectorType>(Extract->getVectorOperandType()); |
| 337 | + if (VecTy && VecTy->getElementType()->isIntegerTy(32) && |
| 338 | + VecTy->getNumElements() == 2) { |
| 339 | + if (auto *Index = dyn_cast<ConstantInt>(Extract->getIndexOperand())) { |
| 340 | + unsigned Idx = Index->getZExtValue(); |
| 341 | + IRBuilder<> Builder(&I); |
| 342 | + assert(dyn_cast<BitCastInst>(Extract->getVectorOperand())); |
| 343 | + auto *Replacement = ReplacedValues[Extract->getVectorOperand()]; |
| 344 | + if (Idx == 0) { |
| 345 | + Value *LowBytes = Builder.CreateTrunc( |
| 346 | + Replacement, Type::getInt32Ty(I.getContext())); |
| 347 | + ReplacedValues[Extract] = LowBytes; |
| 348 | + } else { |
| 349 | + assert(Idx == 1); |
| 350 | + Value *LogicalShiftRight = Builder.CreateLShr( |
| 351 | + Replacement, |
| 352 | + ConstantInt::get( |
| 353 | + Replacement->getType(), |
| 354 | + APInt(Replacement->getType()->getIntegerBitWidth(), 32))); |
| 355 | + Value *HighBytes = Builder.CreateTrunc( |
| 356 | + LogicalShiftRight, Type::getInt32Ty(I.getContext())); |
| 357 | + ReplacedValues[Extract] = HighBytes; |
| 358 | + } |
| 359 | + ToRemove.push_back(Extract); |
| 360 | + } |
| 361 | + } |
| 362 | + } |
| 363 | +} |
320 | 364 | namespace {
|
321 | 365 | class DXILLegalizationPipeline {
|
322 | 366 |
|
@@ -349,6 +393,7 @@ class DXILLegalizationPipeline {
|
349 | 393 | LegalizationPipeline.push_back(downcastI64toI32InsertExtractElements);
|
350 | 394 | LegalizationPipeline.push_back(legalizeFreeze);
|
351 | 395 | LegalizationPipeline.push_back(removeMemSet);
|
| 396 | + LegalizationPipeline.push_back(legalizeGetHighLowi64Bytes); |
352 | 397 | }
|
353 | 398 | };
|
354 | 399 |
|
|
0 commit comments