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 {
12911291 Value* RHS = BinOp->getOperand (1 );
12921292 LHS = Builder.CreateCast (CastOpcode, LHS, IdxTy);
12931293 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+ }
12991302 U->set (BO);
13001303 RecursivelyDeleteTriviallyDeadInstructions (ExtOp);
13011304 Changed = true ;
You can’t perform that action at this time.
0 commit comments