Skip to content

Commit 09e8c0d

Browse files
committed
[InstSimplify] icmp poison, X -> poison
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
1 parent 0873016 commit 09e8c0d

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,10 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
33533353

33543354
Type *ITy = GetCompareTy(LHS); // The return type.
33553355

3356+
// icmp poison, X -> poison
3357+
if (isa<PoisonValue>(RHS))
3358+
return PoisonValue::get(ITy);
3359+
33563360
// For EQ and NE, we can always pick a value for the undef to make the
33573361
// predicate pass or fail, so we can return undef.
33583362
// Matches behavior in llvm::ConstantFoldCompareInstruction.

llvm/test/Transforms/InstCombine/getelementptr.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ define i32* @test_gep_inbounds_of_gep(i32* %base) {
12321232

12331233
define i32* @PR45084(i1 %cond) {
12341234
; CHECK-LABEL: @PR45084(
1235-
; 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
1235+
; 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]+]]
12361236
; CHECK-NEXT: ret i32* [[GEP]]
12371237
;
12381238
%sel = select i1 %cond, %struct.f* @g0, %struct.f* @g1, !prof !0

llvm/test/Transforms/InstCombine/udiv-simplify.ll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ define i64 @test1_PR2274(i32 %x, i32 %g) nounwind {
2727
; CHECK-LABEL: @test1_PR2274(
2828
; CHECK-NEXT: [[Y:%.*]] = lshr i32 [[X:%.*]], 30
2929
; CHECK-NEXT: [[R:%.*]] = udiv i32 [[Y]], [[G:%.*]]
30-
; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[R]] to i64
31-
; CHECK-NEXT: ret i64 [[TMP1]]
30+
; CHECK-NEXT: [[Z:%.*]] = zext i32 [[R]] to i64
31+
; CHECK-NEXT: ret i64 [[Z]]
3232
;
3333
%y = lshr i32 %x, 30
3434
%r = udiv i32 %y, %g
@@ -39,8 +39,8 @@ define i64 @test2_PR2274(i32 %x, i32 %v) nounwind {
3939
; CHECK-LABEL: @test2_PR2274(
4040
; CHECK-NEXT: [[Y:%.*]] = lshr i32 [[X:%.*]], 31
4141
; CHECK-NEXT: [[R:%.*]] = udiv i32 [[Y]], [[V:%.*]]
42-
; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[R]] to i64
43-
; CHECK-NEXT: ret i64 [[TMP1]]
42+
; CHECK-NEXT: [[Z:%.*]] = zext i32 [[R]] to i64
43+
; CHECK-NEXT: ret i64 [[Z]]
4444
;
4545
%y = lshr i32 %x, 31
4646
%r = udiv i32 %y, %v
@@ -67,7 +67,6 @@ define i32 @PR30366(i1 %a) {
6767
; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4857
6868
define i177 @ossfuzz_4857(i177 %X, i177 %Y) {
6969
; CHECK-LABEL: @ossfuzz_4857(
70-
; CHECK-NEXT: store i1 false, i1* undef, align 1
7170
; CHECK-NEXT: ret i177 0
7271
;
7372
%B5 = udiv i177 %Y, -1

llvm/test/Transforms/InstSimplify/icmp.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ define i1 @bitcast_from_single_element_pointer_vector_to_pointer(<1 x i8*> %ptr1
1919
ret i1 %cmp
2020
}
2121

22-
; TODO: these should return poison
23-
2422
define i1 @poison(i32 %x) {
2523
; CHECK-LABEL: @poison(
26-
; CHECK-NEXT: ret i1 undef
24+
; CHECK-NEXT: ret i1 poison
2725
;
2826
%v = icmp eq i32 %x, poison
2927
ret i1 %v
3028
}
3129

3230
define i1 @poison2(i32 %x) {
3331
; CHECK-LABEL: @poison2(
34-
; CHECK-NEXT: ret i1 false
32+
; CHECK-NEXT: ret i1 poison
3533
;
3634
%v = icmp slt i32 %x, poison
3735
ret i1 %v

0 commit comments

Comments
 (0)