diff options
author | David Green <david.green@arm.com> | 2022-10-13 16:41:44 +0100 |
---|---|---|
committer | David Green <david.green@arm.com> | 2022-10-13 16:41:44 +0100 |
commit | 16e4e4ab878aa148f0a4a56540c96a1725a960a2 (patch) | |
tree | 0bfacb931ab0b495c38b7421f35b470222561471 /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
parent | d8cab3f407070c6d80396553ce024e17a0659b04 (diff) | |
download | llvm-16e4e4ab878aa148f0a4a56540c96a1725a960a2.zip llvm-16e4e4ab878aa148f0a4a56540c96a1725a960a2.tar.gz llvm-16e4e4ab878aa148f0a4a56540c96a1725a960a2.tar.bz2 |
[CodeGenPrep] Handle constants in ConvertPhiType
This is a simple addition to the convertPhiTypes in CodeGenPrepare to
consider and convert constants as it converts the phi type. Someone
fixed the bug in the motivating example, so the undef is now a constant
0. This does mean converting between integer and floating point
constants, which may have different materialization.
Differential Revision: https://reviews.llvm.org/D135561
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index f49d127..b9ffb8a 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -6122,6 +6122,7 @@ bool CodeGenPrepare::optimizePhiType( SmallVector<Instruction *, 4> Worklist; Worklist.push_back(cast<Instruction>(I)); SmallPtrSet<PHINode *, 4> PhiNodes; + SmallPtrSet<ConstantData *, 4> Constants; PhiNodes.insert(I); Visited.insert(I); SmallPtrSet<Instruction *, 4> Defs; @@ -6164,9 +6165,10 @@ bool CodeGenPrepare::optimizePhiType( AnyAnchored |= !isa<LoadInst>(OpBC->getOperand(0)) && !isa<ExtractElementInst>(OpBC->getOperand(0)); } - } else if (!isa<UndefValue>(V)) { + } else if (auto *OpC = dyn_cast<ConstantData>(V)) + Constants.insert(OpC); + else return false; - } } } @@ -6208,7 +6210,8 @@ bool CodeGenPrepare::optimizePhiType( // Create all the new phi nodes of the new type, and bitcast any loads to the // correct type. ValueToValueMap ValMap; - ValMap[UndefValue::get(PhiTy)] = UndefValue::get(ConvertTy); + for (ConstantData *C : Constants) + ValMap[C] = ConstantExpr::getCast(Instruction::BitCast, C, ConvertTy); for (Instruction *D : Defs) { if (isa<BitCastInst>(D)) { ValMap[D] = D->getOperand(0); |