Skip to content

Commit 29d1226

Browse files
committed
Fix assertion failure
Given that it's easier to handle than not handle these cases, avoid the order-dependence of transforms.
1 parent bd0a2ff commit 29d1226

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,14 +3201,12 @@ static Value *simplifyICmpWithBinOpOnLHS(CmpInst::Predicate Pred,
32013201
break;
32023202
case ICmpInst::ICMP_EQ:
32033203
case ICmpInst::ICMP_UGE:
3204+
case ICmpInst::ICMP_UGT:
32043205
return getFalse(ITy);
32053206
case ICmpInst::ICMP_NE:
32063207
case ICmpInst::ICMP_ULT:
3207-
return getTrue(ITy);
3208-
case ICmpInst::ICMP_UGT:
32093208
case ICmpInst::ICMP_ULE:
3210-
// UGT/ULE are handled by the more general case just above
3211-
llvm_unreachable("Unexpected UGT/ULE, should have been handled");
3209+
return getTrue(ITy);
32123210
}
32133211
}
32143212
}

llvm/test/Transforms/InstSimplify/compare.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,32 @@ define i1 @lshr_nonzero_ult(i32 %x) {
780780
ret i1 %cmp
781781
}
782782

783+
define i1 @lshr_nonzero_ugt(i32 %x) {
784+
; CHECK-LABEL: @lshr_nonzero_ugt(
785+
; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
786+
; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
787+
; CHECK-NEXT: ret i1 false
788+
;
789+
%x_ne_0 = icmp ne i32 %x, 0
790+
call void @llvm.assume(i1 %x_ne_0)
791+
%lhs = lshr i32 %x, 1
792+
%cmp = icmp ugt i32 %lhs, %x
793+
ret i1 %cmp
794+
}
795+
796+
define i1 @lshr_nonzero_ule(i32 %x) {
797+
; CHECK-LABEL: @lshr_nonzero_ule(
798+
; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
799+
; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
800+
; CHECK-NEXT: ret i1 true
801+
;
802+
%x_ne_0 = icmp ne i32 %x, 0
803+
call void @llvm.assume(i1 %x_ne_0)
804+
%lhs = lshr i32 %x, 1
805+
%cmp = icmp ule i32 %lhs, %x
806+
ret i1 %cmp
807+
}
808+
783809
; Negative test - unknown shift amount
784810
define i1 @lshr_nonzero_neg_unknown(i32 %x, i32 %c) {
785811
; CHECK-LABEL: @lshr_nonzero_neg_unknown(

0 commit comments

Comments
 (0)