Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,11 @@ static Value *foldLogOpOfMaskedICmps(Value *LHS, Value *RHS, bool IsAnd,
APInt NewMask = *ConstB & *ConstD;
if (NewMask == *ConstB)
return LHS;
if (NewMask == *ConstD)
if (NewMask == *ConstD) {
if (IsLogical)
cast<ICmpInst>(RHS)->setSameSign(false);
return RHS;
}
}

if (Mask & AMask_NotAllOnes) {
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/Transforms/InstCombine/sign-test-and-or.ll
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,29 @@ define i1 @test9_logical(i32 %a) {
ret i1 %or.cond
}

define i1 @test9_logical_samesign(i32 %a) {
; CHECK-LABEL: @test9_logical_samesign(
; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[A:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP2]]
;
%masked = and i32 %a, -1073741825
%cmp1 = icmp eq i32 %masked, 0
%cmp2 = icmp samesign sgt i32 %a, -1
%or.cond = select i1 %cmp1, i1 true, i1 %cmp2
ret i1 %or.cond
}

define i1 @test_logical_or_icmp_icmp_samesign(i32 %a) {
; CHECK-LABEL: @test_logical_or_icmp_icmp_samesign(
; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[A:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP2]]
;
%cmp1 = icmp eq i32 %a, 0
%cmp2 = icmp samesign sgt i32 %a, -1
%or = select i1 %cmp1, i1 true, i1 %cmp2
ret i1 %or
}

define i1 @test10(i32 %a) {
; CHECK-LABEL: @test10(
; CHECK-NEXT: [[OR_COND:%.*]] = icmp ult i32 [[A:%.*]], 2
Expand Down