File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -1291,11 +1291,14 @@ bool MemOpt::canonicalizeGEP64(Instruction* I) const {
1291
1291
Value* RHS = BinOp->getOperand (1 );
1292
1292
LHS = Builder.CreateCast (CastOpcode, LHS, IdxTy);
1293
1293
RHS = Builder.CreateCast (CastOpcode, RHS, IdxTy);
1294
- auto BO = cast<BinaryOperator>(Builder.CreateBinOp (BinOpcode, LHS, RHS));
1295
- if (BinOp->hasNoUnsignedWrap ())
1296
- BO->setHasNoUnsignedWrap ();
1297
- if (BinOp->hasNoSignedWrap ())
1298
- BO->setHasNoSignedWrap ();
1294
+ auto BO = Builder.CreateBinOp (BinOpcode, LHS, RHS);
1295
+ // BO can be a constant if both sides are constants
1296
+ if (auto BOP = dyn_cast<BinaryOperator>(BO)) {
1297
+ if (BinOp->hasNoUnsignedWrap ())
1298
+ BOP->setHasNoUnsignedWrap ();
1299
+ if (BinOp->hasNoSignedWrap ())
1300
+ BOP->setHasNoSignedWrap ();
1301
+ }
1299
1302
U->set (BO);
1300
1303
RecursivelyDeleteTriviallyDeadInstructions (ExtOp);
1301
1304
Changed = true ;
You can’t perform that action at this time.
0 commit comments