Skip to content

Commit

Permalink
Fix constant folding for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
makxenov authored and nkaskov committed Jan 4, 2024
1 parent 734d087 commit 48fd30c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/IR/ConstantFold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,11 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
const APFloat &C1V = cast<ConstantFP>(C1)->getValueAPF();
const APFloat &C2V = cast<ConstantFP>(C2)->getValueAPF();
return ConstantInt::get(ResultTy, FCmpInst::compare(C1V, C2V, Predicate));
} else if (isa<ConstantField>(C1) && isa<ConstantField>(C2)) {
const APInt &V1 = cast<ConstantField>(C1)->getValue();
const APInt &V2 = cast<ConstantField>(C2)->getValue();
// TODO(maksenov): maybe add field-specific logic to comparison
return ConstantInt::get(ResultTy, ICmpInst::compare(V1, V2, Predicate));
} else if (auto *C1VTy = dyn_cast<VectorType>(C1->getType())) {

// Fast path for splatted constants.
Expand Down

0 comments on commit 48fd30c

Please sign in to comment.