[InstSimplify] icmp poison, X -> poison
authorJuneyoung Lee <aqjune@gmail.com>
Sun, 20 Jun 2021 06:29:05 +0000 (15:29 +0900)
committerJuneyoung Lee <aqjune@gmail.com>
Sun, 20 Jun 2021 06:39:07 +0000 (15:39 +0900)
This adds a simple transformation from icmp with poison constant to poison.
Comparing poison with something else is poison, so this is okay.

https://alive2.llvm.org/ce/z/e8iReb
https://alive2.llvm.org/ce/z/q4MurY

llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/getelementptr.ll
llvm/test/Transforms/InstCombine/udiv-simplify.ll
llvm/test/Transforms/InstSimplify/icmp.ll

index 895218b..a9713c8 100644 (file)
@@ -3353,6 +3353,10 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
 
   Type *ITy = GetCompareTy(LHS); // The return type.
 
+  // icmp poison, X -> poison
+  if (isa<PoisonValue>(RHS))
+    return PoisonValue::get(ITy);
+
   // For EQ and NE, we can always pick a value for the undef to make the
   // predicate pass or fail, so we can return undef.
   // Matches behavior in llvm::ConstantFoldCompareInstruction.
index f3bdcf3..02259f6 100644 (file)
@@ -1232,7 +1232,7 @@ define i32* @test_gep_inbounds_of_gep(i32* %base) {
 
 define i32* @PR45084(i1 %cond) {
 ; CHECK-LABEL: @PR45084(
-; CHECK-NEXT:    [[GEP:%.*]] = select i1 [[COND:%.*]], i32* getelementptr inbounds ([[STRUCT_F:%.*]], %struct.f* @g0, i64 0, i32 0), i32* getelementptr inbounds ([[STRUCT_F]], %struct.f* @g1, i64 0, i32 0), !prof !0
+; CHECK-NEXT:    [[GEP:%.*]] = select i1 [[COND:%.*]], i32* getelementptr inbounds ([[STRUCT_F:%.*]], %struct.f* @g0, i64 0, i32 0), i32* getelementptr inbounds ([[STRUCT_F]], %struct.f* @g1, i64 0, i32 0), !prof [[PROF0:![0-9]+]]
 ; CHECK-NEXT:    ret i32* [[GEP]]
 ;
   %sel = select i1 %cond, %struct.f* @g0, %struct.f* @g1, !prof !0
index 8fd604b..96bc479 100644 (file)
@@ -27,8 +27,8 @@ define i64 @test1_PR2274(i32 %x, i32 %g) nounwind {
 ; CHECK-LABEL: @test1_PR2274(
 ; CHECK-NEXT:    [[Y:%.*]] = lshr i32 [[X:%.*]], 30
 ; CHECK-NEXT:    [[R:%.*]] = udiv i32 [[Y]], [[G:%.*]]
-; CHECK-NEXT:    [[TMP1:%.*]] = zext i32 [[R]] to i64
-; CHECK-NEXT:    ret i64 [[TMP1]]
+; CHECK-NEXT:    [[Z:%.*]] = zext i32 [[R]] to i64
+; CHECK-NEXT:    ret i64 [[Z]]
 ;
   %y = lshr i32 %x, 30
   %r = udiv i32 %y, %g
@@ -39,8 +39,8 @@ define i64 @test2_PR2274(i32 %x, i32 %v) nounwind {
 ; CHECK-LABEL: @test2_PR2274(
 ; CHECK-NEXT:    [[Y:%.*]] = lshr i32 [[X:%.*]], 31
 ; CHECK-NEXT:    [[R:%.*]] = udiv i32 [[Y]], [[V:%.*]]
-; CHECK-NEXT:    [[TMP1:%.*]] = zext i32 [[R]] to i64
-; CHECK-NEXT:    ret i64 [[TMP1]]
+; CHECK-NEXT:    [[Z:%.*]] = zext i32 [[R]] to i64
+; CHECK-NEXT:    ret i64 [[Z]]
 ;
   %y = lshr i32 %x, 31
   %r = udiv i32 %y, %v
@@ -67,7 +67,6 @@ define i32 @PR30366(i1 %a) {
 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4857
 define i177 @ossfuzz_4857(i177 %X, i177 %Y) {
 ; CHECK-LABEL: @ossfuzz_4857(
-; CHECK-NEXT:    store i1 false, i1* undef, align 1
 ; CHECK-NEXT:    ret i177 0
 ;
   %B5 = udiv i177 %Y, -1
index caa96b4..b7cab48 100644 (file)
@@ -19,11 +19,9 @@ define i1 @bitcast_from_single_element_pointer_vector_to_pointer(<1 x i8*> %ptr1
   ret i1 %cmp
 }
 
-; TODO: these should return poison
-
 define i1 @poison(i32 %x) {
 ; CHECK-LABEL: @poison(
-; CHECK-NEXT:    ret i1 undef
+; CHECK-NEXT:    ret i1 poison
 ;
   %v = icmp eq i32 %x, poison
   ret i1 %v
@@ -31,7 +29,7 @@ define i1 @poison(i32 %x) {
 
 define i1 @poison2(i32 %x) {
 ; CHECK-LABEL: @poison2(
-; CHECK-NEXT:    ret i1 false
+; CHECK-NEXT:    ret i1 poison
 ;
   %v = icmp slt i32 %x, poison
   ret i1 %v