|
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"
|
@@ -419,6 +421,49 @@ static void updateFnegToFsub(Instruction &I,
|
419 | 421 | ToRemove.push_back(&I);
|
420 | 422 | }
|
421 | 423 |
|
| 424 | +static void |
| 425 | +legalizeGetHighLowi64Bytes(Instruction &I, |
| 426 | + SmallVectorImpl<Instruction *> &ToRemove, |
| 427 | + DenseMap<Value *, Value *> &ReplacedValues) { |
| 428 | + if (auto *BitCast = dyn_cast<BitCastInst>(&I)) { |
| 429 | + if (BitCast->getDestTy() == |
| 430 | + FixedVectorType::get(Type::getInt32Ty(I.getContext()), 2) && |
| 431 | + BitCast->getSrcTy()->isIntegerTy(64)) { |
| 432 | + ToRemove.push_back(BitCast); |
| 433 | + ReplacedValues[BitCast] = BitCast->getOperand(0); |
| 434 | + } |
| 435 | + } |
| 436 | + |
| 437 | + if (auto *Extract = dyn_cast<ExtractElementInst>(&I)) { |
| 438 | + auto *VecTy = dyn_cast<FixedVectorType>(Extract->getVectorOperandType()); |
| 439 | + if (VecTy && VecTy->getElementType()->isIntegerTy(32) && |
| 440 | + VecTy->getNumElements() == 2) { |
| 441 | + if (auto *Index = dyn_cast<ConstantInt>(Extract->getIndexOperand())) { |
| 442 | + unsigned Idx = Index->getZExtValue(); |
| 443 | + IRBuilder<> Builder(&I); |
| 444 | + assert(dyn_cast<BitCastInst>(Extract->getVectorOperand())); |
| 445 | + auto *Replacement = ReplacedValues[Extract->getVectorOperand()]; |
| 446 | + if (Idx == 0) { |
| 447 | + Value *LowBytes = Builder.CreateTrunc( |
| 448 | + Replacement, Type::getInt32Ty(I.getContext())); |
| 449 | + ReplacedValues[Extract] = LowBytes; |
| 450 | + } else { |
| 451 | + assert(Idx == 1); |
| 452 | + Value *LogicalShiftRight = Builder.CreateLShr( |
| 453 | + Replacement, |
| 454 | + ConstantInt::get( |
| 455 | + Replacement->getType(), |
| 456 | + APInt(Replacement->getType()->getIntegerBitWidth(), 32))); |
| 457 | + Value *HighBytes = Builder.CreateTrunc( |
| 458 | + LogicalShiftRight, Type::getInt32Ty(I.getContext())); |
| 459 | + ReplacedValues[Extract] = HighBytes; |
| 460 | + } |
| 461 | + ToRemove.push_back(Extract); |
| 462 | + } |
| 463 | + } |
| 464 | + } |
| 465 | +} |
| 466 | + |
422 | 467 | namespace {
|
423 | 468 | class DXILLegalizationPipeline {
|
424 | 469 |
|
@@ -453,6 +498,7 @@ class DXILLegalizationPipeline {
|
453 | 498 | LegalizationPipeline.push_back(legalizeMemCpy);
|
454 | 499 | LegalizationPipeline.push_back(removeMemSet);
|
455 | 500 | LegalizationPipeline.push_back(updateFnegToFsub);
|
| 501 | + LegalizationPipeline.push_back(legalizeGetHighLowi64Bytes); |
456 | 502 | }
|
457 | 503 | };
|
458 | 504 |
|
|
0 commit comments