@@ -33,16 +33,19 @@ static bool fixI8TruncUseChain(Instruction &I,
33
33
std::stack<Instruction *> &ToRemove,
34
34
std::map<Value *, Value *> &ReplacedValues) {
35
35
36
+ auto *Cmp = dyn_cast<CmpInst>(&I);
37
+
36
38
if (auto *Trunc = dyn_cast<TruncInst>(&I)) {
37
39
if (Trunc->getDestTy ()->isIntegerTy (8 )) {
38
40
ReplacedValues[Trunc] = Trunc->getOperand (0 );
39
41
ToRemove.push (Trunc);
40
42
}
41
- } else if (I.getType ()->isIntegerTy (8 )) {
43
+ } else if (I.getType ()->isIntegerTy (8 ) ||
44
+ (Cmp && Cmp->getOperand (0 )->getType ()->isIntegerTy (8 ))) {
42
45
IRBuilder<> Builder (&I);
43
46
44
47
std::vector<Value *> NewOperands;
45
- Type *InstrType = nullptr ;
48
+ Type *InstrType = IntegerType::get (I. getContext (), 32 ) ;
46
49
for (unsigned OpIdx = 0 ; OpIdx < I.getNumOperands (); ++OpIdx) {
47
50
Value *Op = I.getOperand (OpIdx);
48
51
if (ReplacedValues.count (Op)) {
@@ -66,23 +69,21 @@ static bool fixI8TruncUseChain(Instruction &I,
66
69
if (auto *BO = dyn_cast<BinaryOperator>(&I))
67
70
NewInst =
68
71
Builder.CreateBinOp (BO->getOpcode (), NewOperands[0 ], NewOperands[1 ]);
69
- else if (auto * Cmp = dyn_cast<CmpInst>(&I))
72
+ else if (Cmp) {
70
73
NewInst = Builder.CreateCmp (Cmp->getPredicate (), NewOperands[0 ],
71
74
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))
76
77
NewInst = Builder.CreateUnOp (UnaryOp->getOpcode (), NewOperands[0 ]);
77
78
78
79
if (NewInst) {
79
80
ReplacedValues[&I] = NewInst;
80
81
ToRemove.push (&I);
81
82
}
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 )]);
86
87
}
87
88
}
88
89
0 commit comments