Skip to content

Commit

Permalink
[InstCombine] add assert/test for zext to i1
Browse files Browse the repository at this point in the history
This is a test to verify that we do not crash with the
problem noted in issue #57986. The root problem should
be fixed with a prior change to InstSimplify.
  • Loading branch information
rotateright committed Sep 26, 2022
1 parent 222e1c7 commit def6cbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
Value *I0 = II->getArgOperand(0), *I1 = II->getArgOperand(1);
// umin(x, 1) == zext(x != 0)
if (match(I1, m_One())) {
assert(II->getType()->getScalarSizeInBits() != 1 &&
"Expected simplify of umin with max constant");
Value *Zero = Constant::getNullValue(I0->getType());
Value *Cmp = Builder.CreateICmpNE(I0, Zero);
return CastInst::Create(Instruction::ZExt, Cmp, II->getType());
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -passes=instcombine < %s | FileCheck %s

declare i1 @llvm.umin.i1(i1, i1)
declare i8 @llvm.umin.i8(i8, i8)
declare i8 @llvm.umax.i8(i8, i8)
declare i8 @llvm.smin.i8(i8, i8)
Expand Down Expand Up @@ -2477,3 +2478,15 @@ define <3 x i8> @smin_unary_shuffle_ops_uses(<3 x i8> %x, <3 x i8> %y) {
%r = call <3 x i8> @llvm.smin.v3i8(<3 x i8> %sx, <3 x i8> %sy)
ret <3 x i8> %r
}

; This would assert/crash because we tried to zext to i1.

@g = external dso_local global i32, align 4

define i1 @PR57986() {
; CHECK-LABEL: @PR57986(
; CHECK-NEXT: ret i1 ptrtoint (i32* @g to i1)
;
%umin = call i1 @llvm.umin.i1(i1 ptrtoint (i32* @g to i1), i1 true)
ret i1 %umin
}

0 comments on commit def6cbd

Please sign in to comment.