Skip to content

Commit 3a72cd2

Browse files
agrabezhigcbot
authored andcommitted
Restrict Add reassociation if it clears NSW flag
Do not apply reassociation when add instructions have NSW flag, since it will be cleared for new add instruction.
1 parent 4f153ac commit 3a72cd2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

IGC/Compiler/CustomSafeOptPass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,9 @@ void CustomSafeOptPass::visitBinaryOperator(BinaryOperator& I)
13691369
llvm::Instruction* nextInst = llvm::dyn_cast<llvm::Instruction>(*(I.user_begin()));
13701370
if (nextInst && nextInst->getOpcode() == Instruction::Add)
13711371
{
1372+
// do not apply if any add instruction has NSW flag since we can't save it
1373+
if ((isa<OverflowingBinaryOperator>(I) && I.hasNoSignedWrap()) || nextInst->hasNoSignedWrap())
1374+
return;
13721375
ConstantInt* secondSrc0imm = dyn_cast<ConstantInt>(nextInst->getOperand(0));
13731376
ConstantInt* secondSrc1imm = dyn_cast<ConstantInt>(nextInst->getOperand(1));
13741377
// found 2 add instructions to swap srcs

0 commit comments

Comments
 (0)