@@ -87,9 +87,8 @@ static void fixI8UseChain(Instruction &I,
87
87
return ;
88
88
}
89
89
90
- if (auto *Load = dyn_cast<LoadInst>(&I)) {
91
- if (!I.getType ()->isIntegerTy (8 ))
92
- return ;
90
+ if (auto *Load = dyn_cast<LoadInst>(&I);
91
+ Load && I.getType ()->isIntegerTy (8 )) {
93
92
SmallVector<Value *> NewOperands;
94
93
ProcessOperands (NewOperands);
95
94
Type *ElementType = NewOperands[0 ]->getType ();
@@ -103,6 +102,31 @@ static void fixI8UseChain(Instruction &I,
103
102
return ;
104
103
}
105
104
105
+ if (auto *Load = dyn_cast<LoadInst>(&I);
106
+ Load && isa<ConstantExpr>(Load->getPointerOperand ())) {
107
+ auto *CE = dyn_cast<ConstantExpr>(Load->getPointerOperand ());
108
+ if (!(CE->getOpcode () == Instruction::GetElementPtr))
109
+ return ;
110
+ auto *GEP = dyn_cast<GEPOperator>(CE);
111
+ if (!GEP->getSourceElementType ()->isIntegerTy (8 ))
112
+ return ;
113
+
114
+ Type *ElementType = Load->getType ();
115
+ ConstantInt *Offset = dyn_cast<ConstantInt>(GEP->getOperand (1 ));
116
+ uint32_t ByteOffset = Offset->getZExtValue ();
117
+ uint32_t ElemSize = Load->getDataLayout ().getTypeAllocSize (ElementType);
118
+ uint32_t Index = ByteOffset / ElemSize;
119
+ Value *NewGEP = Builder.CreateGEP (ElementType, GEP->getPointerOperand (),
120
+ Builder.getInt32 (Index), GEP->getName (),
121
+ GEP->getNoWrapFlags ());
122
+
123
+ LoadInst *NewLoad = Builder.CreateLoad (ElementType, NewGEP);
124
+ ReplacedValues[Load] = NewLoad;
125
+ Load->replaceAllUsesWith (NewLoad);
126
+ ToRemove.push_back (Load);
127
+ return ;
128
+ }
129
+
106
130
if (auto *BO = dyn_cast<BinaryOperator>(&I)) {
107
131
if (!I.getType ()->isIntegerTy (8 ))
108
132
return ;
@@ -178,6 +202,8 @@ static void fixI8UseChain(Instruction &I,
178
202
Type *ElementType = BasePtr->getType ();
179
203
if (auto *AI = dyn_cast<AllocaInst>(BasePtr))
180
204
ElementType = AI->getAllocatedType ();
205
+ if (auto *GV = dyn_cast<GlobalVariable>(BasePtr))
206
+ ElementType = GV->getValueType ();
181
207
if (auto *ArrTy = dyn_cast<ArrayType>(ElementType))
182
208
ElementType = ArrTy->getArrayElementType ();
183
209
0 commit comments