@@ -33,16 +33,19 @@ static bool fixI8TruncUseChain(Instruction &I,
3333 std::stack<Instruction *> &ToRemove,
3434 std::map<Value *, Value *> &ReplacedValues) {
3535
36+ auto *Cmp = dyn_cast<CmpInst>(&I);
37+
3638 if (auto *Trunc = dyn_cast<TruncInst>(&I)) {
3739 if (Trunc->getDestTy ()->isIntegerTy (8 )) {
3840 ReplacedValues[Trunc] = Trunc->getOperand (0 );
3941 ToRemove.push (Trunc);
4042 }
41- } else if (I.getType ()->isIntegerTy (8 )) {
43+ } else if (I.getType ()->isIntegerTy (8 ) ||
44+ (Cmp && Cmp->getOperand (0 )->getType ()->isIntegerTy (8 ))) {
4245 IRBuilder<> Builder (&I);
4346
4447 std::vector<Value *> NewOperands;
45- Type *InstrType = nullptr ;
48+ Type *InstrType = IntegerType::get (I. getContext (), 32 ) ;
4649 for (unsigned OpIdx = 0 ; OpIdx < I.getNumOperands (); ++OpIdx) {
4750 Value *Op = I.getOperand (OpIdx);
4851 if (ReplacedValues.count (Op)) {
@@ -66,23 +69,21 @@ static bool fixI8TruncUseChain(Instruction &I,
6669 if (auto *BO = dyn_cast<BinaryOperator>(&I))
6770 NewInst =
6871 Builder.CreateBinOp (BO->getOpcode (), NewOperands[0 ], NewOperands[1 ]);
69- else if (auto * Cmp = dyn_cast<CmpInst>(&I))
72+ else if (Cmp) {
7073 NewInst = Builder.CreateCmp (Cmp->getPredicate (), NewOperands[0 ],
7174 NewOperands[1 ]);
72- else if (auto *Cast = dyn_cast<CastInst>(&I))
73- NewInst = Builder.CreateCast (Cast->getOpcode (), NewOperands[0 ],
74- Cast->getDestTy ());
75- else if (auto *UnaryOp = dyn_cast<UnaryOperator>(&I))
75+ Cmp->replaceAllUsesWith (NewInst);
76+ } else if (auto *UnaryOp = dyn_cast<UnaryOperator>(&I))
7677 NewInst = Builder.CreateUnOp (UnaryOp->getOpcode (), NewOperands[0 ]);
7778
7879 if (NewInst) {
7980 ReplacedValues[&I] = NewInst;
8081 ToRemove.push (&I);
8182 }
82- } else if (auto *Sext = dyn_cast<SExtInst >(&I)) {
83- if (Sext ->getSrcTy ()->isIntegerTy (8 )) {
84- ToRemove.push (Sext );
85- Sext ->replaceAllUsesWith (ReplacedValues[Sext ->getOperand (0 )]);
83+ } else if (auto *Cast = dyn_cast<CastInst >(&I)) {
84+ if (Cast ->getSrcTy ()->isIntegerTy (8 )) {
85+ ToRemove.push (Cast );
86+ Cast ->replaceAllUsesWith (ReplacedValues[Cast ->getOperand (0 )]);
8687 }
8788 }
8889
0 commit comments