|
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" |
@@ -510,6 +512,49 @@ static void updateFnegToFsub(Instruction &I, |
510 | 512 | ToRemove.push_back(&I); |
511 | 513 | } |
512 | 514 |
|
| 515 | +static void |
| 516 | +legalizeGetHighLowi64Bytes(Instruction &I, |
| 517 | + SmallVectorImpl<Instruction *> &ToRemove, |
| 518 | + DenseMap<Value *, Value *> &ReplacedValues) { |
| 519 | + if (auto *BitCast = dyn_cast<BitCastInst>(&I)) { |
| 520 | + if (BitCast->getDestTy() == |
| 521 | + FixedVectorType::get(Type::getInt32Ty(I.getContext()), 2) && |
| 522 | + BitCast->getSrcTy()->isIntegerTy(64)) { |
| 523 | + ToRemove.push_back(BitCast); |
| 524 | + ReplacedValues[BitCast] = BitCast->getOperand(0); |
| 525 | + } |
| 526 | + } |
| 527 | + |
| 528 | + if (auto *Extract = dyn_cast<ExtractElementInst>(&I)) { |
| 529 | + auto *VecTy = dyn_cast<FixedVectorType>(Extract->getVectorOperandType()); |
| 530 | + if (VecTy && VecTy->getElementType()->isIntegerTy(32) && |
| 531 | + VecTy->getNumElements() == 2) { |
| 532 | + if (auto *Index = dyn_cast<ConstantInt>(Extract->getIndexOperand())) { |
| 533 | + unsigned Idx = Index->getZExtValue(); |
| 534 | + IRBuilder<> Builder(&I); |
| 535 | + assert(dyn_cast<BitCastInst>(Extract->getVectorOperand())); |
| 536 | + auto *Replacement = ReplacedValues[Extract->getVectorOperand()]; |
| 537 | + if (Idx == 0) { |
| 538 | + Value *LowBytes = Builder.CreateTrunc( |
| 539 | + Replacement, Type::getInt32Ty(I.getContext())); |
| 540 | + ReplacedValues[Extract] = LowBytes; |
| 541 | + } else { |
| 542 | + assert(Idx == 1); |
| 543 | + Value *LogicalShiftRight = Builder.CreateLShr( |
| 544 | + Replacement, |
| 545 | + ConstantInt::get( |
| 546 | + Replacement->getType(), |
| 547 | + APInt(Replacement->getType()->getIntegerBitWidth(), 32))); |
| 548 | + Value *HighBytes = Builder.CreateTrunc( |
| 549 | + LogicalShiftRight, Type::getInt32Ty(I.getContext())); |
| 550 | + ReplacedValues[Extract] = HighBytes; |
| 551 | + } |
| 552 | + ToRemove.push_back(Extract); |
| 553 | + } |
| 554 | + } |
| 555 | + } |
| 556 | +} |
| 557 | + |
513 | 558 | namespace { |
514 | 559 | class DXILLegalizationPipeline { |
515 | 560 |
|
@@ -544,6 +589,7 @@ class DXILLegalizationPipeline { |
544 | 589 | LegalizationPipeline.push_back(legalizeMemCpy); |
545 | 590 | LegalizationPipeline.push_back(removeMemSet); |
546 | 591 | LegalizationPipeline.push_back(updateFnegToFsub); |
| 592 | + LegalizationPipeline.push_back(legalizeGetHighLowi64Bytes); |
547 | 593 | } |
548 | 594 | }; |
549 | 595 |
|
|
0 commit comments