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

Commit 206ece1

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 (cherry picked from commit 9dfeae4)
1 parent 3f7ae96 commit 206ece1

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
@@ -2378,7 +2378,8 @@ Value *InstCombiner::foldXorOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
23782378
Value *LHS0 = LHS->getOperand(0), *LHS1 = LHS->getOperand(1);
23792379
Value *RHS0 = RHS->getOperand(0), *RHS1 = RHS->getOperand(1);
23802380
if ((LHS->hasOneUse() || RHS->hasOneUse()) &&
2381-
LHS0->getType() == RHS0->getType()) {
2381+
LHS0->getType() == RHS0->getType() &&
2382+
LHS0->getType()->isIntOrIntVectorTy()) {
23822383
// (X > -1) ^ (Y > -1) --> (X ^ Y) < 0
23832384
// (X < 0) ^ (Y < 0) --> (X ^ Y) < 0
23842385
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)