[llvm] def6cbd - [InstCombine] add assert/test for zext to i1

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 26 13:09:56 PDT 2022


Author: Sanjay Patel
Date: 2022-09-26T16:01:25-04:00
New Revision: def6cbd2bd7656a942fe283062ea321ef9a172fc

URL: https://github.com/llvm/llvm-project/commit/def6cbd2bd7656a942fe283062ea321ef9a172fc
DIFF: https://github.com/llvm/llvm-project/commit/def6cbd2bd7656a942fe283062ea321ef9a172fc.diff

LOG: [InstCombine] add assert/test for zext to i1

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.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/test/Transforms/InstCombine/minmax-intrinsics.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index f28ce858a169a..7984dcdb8987a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -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());

diff  --git a/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll b/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
index 7fb4f80c5cadb..2f84f415f76a7 100644
--- a/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
@@ -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)
@@ -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.
+
+ at 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
+}


        


More information about the llvm-commits mailing list