Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 9dfeae4

Browse files
committed
[InstCombine] Fix IC trying to create a xor of pointer types.
rdar://42473741 Differential Revision: https://reviews.llvm.org/D50775 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339796 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 41df26a commit 9dfeae4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2487,7 +2487,8 @@ Value *InstCombiner::foldXorOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
24872487
Value *LHS0 = LHS->getOperand(0), *LHS1 = LHS->getOperand(1);
24882488
Value *RHS0 = RHS->getOperand(0), *RHS1 = RHS->getOperand(1);
24892489
if ((LHS->hasOneUse() || RHS->hasOneUse()) &&
2490-
LHS0->getType() == RHS0->getType()) {
2490+
LHS0->getType() == RHS0->getType() &&
2491+
LHS0->getType()->isIntOrIntVectorTy()) {
24912492
// (X > -1) ^ (Y > -1) --> (X ^ Y) < 0
24922493
// (X < 0) ^ (Y < 0) --> (X ^ Y) < 0
24932494
if ((PredL == CmpInst::ICMP_SGT && match(LHS1, m_AllOnes()) &&

test/Transforms/InstCombine/xor-icmps.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,16 @@ define i1 @test14(i8 %A, i8 %B) {
158158
ret i1 %E
159159
}
160160

161+
define i1 @xor_icmp_ptr(i8* %c, i8* %d) {
162+
; CHECK-LABEL: @xor_icmp_ptr(
163+
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8* [[C:%.*]], null
164+
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8* [[D:%.*]], null
165+
; CHECK-NEXT: [[XOR:%.*]] = xor i1 [[CMP]], [[CMP1]]
166+
; CHECK-NEXT: ret i1 [[XOR]]
167+
;
168+
%cmp = icmp slt i8* %c, null
169+
%cmp1 = icmp slt i8* %d, null
170+
%xor = xor i1 %cmp, %cmp1
171+
ret i1 %xor
172+
}
173+

0 commit comments

Comments
 (0)