[ConstantFold] Fix comparison between special pointer constants

This code was assuming that the LHS would always be one of
GlobalVariable, BlockAddress or ConstantExpr. However, it can
also be a special constant like dso_local_equivalent or no_cfi.
Make sure this is handled gracefully.
This commit is contained in:
Nikita Popov 2024-03-19 12:20:00 +01:00
parent c9bdeabdf4
commit 00ca80938b
2 changed files with 9 additions and 2 deletions

View File

@ -1154,10 +1154,9 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2) {
GV->getType()->getAddressSpace()))
return ICmpInst::ICMP_UGT;
}
} else {
} else if (auto *CE1 = dyn_cast<ConstantExpr>(V1)) {
// Ok, the LHS is known to be a constantexpr. The RHS can be any of a
// constantexpr, a global, block address, or a simple constant.
ConstantExpr *CE1 = cast<ConstantExpr>(V1);
Constant *CE1Op0 = CE1->getOperand(0);
switch (CE1->getOpcode()) {

View File

@ -298,3 +298,11 @@ bb:
%cmp = icmp eq ptr blockaddress(@blockaddr_no_cfi, %bb), no_cfi @func
ret i1 %cmp
}
define i1 @global_no_cfi_dso_local_equivalent() {
; CHECK-LABEL: @global_no_cfi_dso_local_equivalent(
; CHECK-NEXT: ret i1 icmp eq (ptr dso_local_equivalent @func, ptr no_cfi @func)
;
%cmp = icmp eq ptr dso_local_equivalent @func, no_cfi @func
ret i1 %cmp
}