Skip to content

Commit af50d6e

Browse files
committed
[SeparateConstOffsetFromGEP] Avoid use of ConstantExpr::getCast()
Try to constant fold, otherwise fall back to generating an instruction.
1 parent 0eb5168 commit af50d6e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,15 +661,16 @@ Value *ConstantOffsetExtractor::applyExts(Value *V) {
661661
// in the reversed order.
662662
for (CastInst *I : llvm::reverse(ExtInsts)) {
663663
if (Constant *C = dyn_cast<Constant>(Current)) {
664-
// If Current is a constant, apply s/zext using ConstantExpr::getCast.
665-
// ConstantExpr::getCast emits a ConstantInt if C is a ConstantInt.
666-
Current = ConstantExpr::getCast(I->getOpcode(), C, I->getType());
667-
} else {
668-
Instruction *Ext = I->clone();
669-
Ext->setOperand(0, Current);
670-
Ext->insertBefore(IP);
671-
Current = Ext;
664+
// Try to constant fold the cast.
665+
Current = ConstantFoldCastOperand(I->getOpcode(), C, I->getType(), DL);
666+
if (Current)
667+
continue;
672668
}
669+
670+
Instruction *Ext = I->clone();
671+
Ext->setOperand(0, Current);
672+
Ext->insertBefore(IP);
673+
Current = Ext;
673674
}
674675
return Current;
675676
}

0 commit comments

Comments
 (0)