Skip to content

Commit 7c7e97c

Browse files
itsimbalsys_zuul
authored andcommitted
The code in MemOpt::canonicalizeGEP64 doesn't handle a case when
operands are constants and an operation is folded into a constant also. Change-Id: I4c7f565f270d440079ca6cdfbc1b4489a1cba1b7
1 parent 8f4367c commit 7c7e97c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

IGC/Compiler/CISACodeGen/MemOpt.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)