Skip to content

Commit 00ca809

Browse files
committed
[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.
1 parent c9bdeab commit 00ca809

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,10 +1154,9 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2) {
11541154
GV->getType()->getAddressSpace()))
11551155
return ICmpInst::ICMP_UGT;
11561156
}
1157-
} else {
1157+
} else if (auto *CE1 = dyn_cast<ConstantExpr>(V1)) {
11581158
// Ok, the LHS is known to be a constantexpr. The RHS can be any of a
11591159
// constantexpr, a global, block address, or a simple constant.
1160-
ConstantExpr *CE1 = cast<ConstantExpr>(V1);
11611160
Constant *CE1Op0 = CE1->getOperand(0);
11621161

11631162
switch (CE1->getOpcode()) {

llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,11 @@ bb:
298298
%cmp = icmp eq ptr blockaddress(@blockaddr_no_cfi, %bb), no_cfi @func
299299
ret i1 %cmp
300300
}
301+
302+
define i1 @global_no_cfi_dso_local_equivalent() {
303+
; CHECK-LABEL: @global_no_cfi_dso_local_equivalent(
304+
; CHECK-NEXT: ret i1 icmp eq (ptr dso_local_equivalent @func, ptr no_cfi @func)
305+
;
306+
%cmp = icmp eq ptr dso_local_equivalent @func, no_cfi @func
307+
ret i1 %cmp
308+
}

0 commit comments

Comments
 (0)