From 84b285d6eb9d52f467fa710f2c9f490a0584c0b2 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Thu, 30 Dec 2021 13:25:57 +0000 Subject: [PATCH] [GVN] Set phi entries of unreachable predecessors to poison instead of undef This matches NewGVN's behavior. --- llvm/lib/Transforms/Scalar/GVN.cpp | 6 +++--- llvm/test/Transforms/GVN/assume-equal.ll | 2 +- llvm/test/Transforms/GVN/calls-nonlocal.ll | 2 +- llvm/test/Transforms/GVN/condprop.ll | 2 +- llvm/test/Transforms/GVN/equality-assume.ll | 2 +- llvm/test/Transforms/GVN/preserve-memoryssa.ll | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 00506fb..ee7a2e4 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1769,7 +1769,7 @@ bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) { // Insert a new store to null instruction before the load to indicate that // this code is not reachable. FIXME: We could insert unreachable // instruction directly because we can modify the CFG. - auto *NewS = new StoreInst(UndefValue::get(Int8Ty), + auto *NewS = new StoreInst(PoisonValue::get(Int8Ty), Constant::getNullValue(Int8Ty->getPointerTo()), IntrinsicI); if (MSSAU) { @@ -2991,12 +2991,12 @@ void GVNPass::addDeadBlock(BasicBlock *BB) { } } - // Now undef the incoming values from the dead predecessors. + // Now poison the incoming values from the dead predecessors. for (BasicBlock *P : predecessors(B)) { if (!DeadBlocks.count(P)) continue; for (PHINode &Phi : B->phis()) { - Phi.setIncomingValueForBlock(P, UndefValue::get(Phi.getType())); + Phi.setIncomingValueForBlock(P, PoisonValue::get(Phi.getType())); if (MD) MD->invalidateCachedPointerInfo(&Phi); } diff --git a/llvm/test/Transforms/GVN/assume-equal.ll b/llvm/test/Transforms/GVN/assume-equal.ll index 941f14c..b51fded 100644 --- a/llvm/test/Transforms/GVN/assume-equal.ll +++ b/llvm/test/Transforms/GVN/assume-equal.ll @@ -217,7 +217,7 @@ entry: bb2: ; CHECK-NOT: %cmp3 = %cmp3 = icmp eq i32 %p, 43 - ; CHECK: store i8 undef, i8* null + ; CHECK: store i8 poison, i8* null call void @llvm.assume(i1 %cmp3) ret i32 15 bb3: diff --git a/llvm/test/Transforms/GVN/calls-nonlocal.ll b/llvm/test/Transforms/GVN/calls-nonlocal.ll index 81057dd..952f674 100644 --- a/llvm/test/Transforms/GVN/calls-nonlocal.ll +++ b/llvm/test/Transforms/GVN/calls-nonlocal.ll @@ -68,7 +68,7 @@ return: ; preds = %bb27 ; CHECK: bb26: ; CHECK: br label %bb27 ; CHECK: bb27: -; CHECK: %tmp.0 = phi i32 [ 11, %bb26 ], [ undef, %bb24 ], [ undef, %bb14 ], [ %g, %bb ] +; CHECK: %tmp.0 = phi i32 [ 11, %bb26 ], [ poison, %bb24 ], [ poison, %bb14 ], [ %g, %bb ] ; CHECK: ret i32 %tmp.0 ; CHECK: } diff --git a/llvm/test/Transforms/GVN/condprop.ll b/llvm/test/Transforms/GVN/condprop.ll index 04ecb3c..8a730ae 100644 --- a/llvm/test/Transforms/GVN/condprop.ll +++ b/llvm/test/Transforms/GVN/condprop.ll @@ -31,7 +31,7 @@ define i32 @test1() nounwind { ; CHECK: bb7: ; CHECK-NEXT: br label [[BB8]] ; CHECK: bb8: -; CHECK-NEXT: [[DOT0:%.*]] = phi i32 [ [[TMP0]], [[BB7]] ], [ undef, [[BB6]] ], [ undef, [[BB4]] ], [ 4, [[BB2]] ], [ 5, [[BB]] ] +; CHECK-NEXT: [[DOT0:%.*]] = phi i32 [ [[TMP0]], [[BB7]] ], [ poison, [[BB6]] ], [ poison, [[BB4]] ], [ 4, [[BB2]] ], [ 5, [[BB]] ] ; CHECK-NEXT: ret i32 [[DOT0]] ; entry: diff --git a/llvm/test/Transforms/GVN/equality-assume.ll b/llvm/test/Transforms/GVN/equality-assume.ll index ee2cb06..ee55d5d 100644 --- a/llvm/test/Transforms/GVN/equality-assume.ll +++ b/llvm/test/Transforms/GVN/equality-assume.ll @@ -149,7 +149,7 @@ merge: define i32 @conflicting_constants(i32* %p) { ; CHECK-LABEL: @conflicting_constants( -; CHECK-NEXT: store i8 undef, i8* null +; CHECK-NEXT: store i8 poison, i8* null ; CHECK-NEXT: br i1 undef, label [[TAKEN:%.*]], label [[MERGE:%.*]] ; CHECK: taken: ; CHECK-NEXT: br label [[MERGE]] diff --git a/llvm/test/Transforms/GVN/preserve-memoryssa.ll b/llvm/test/Transforms/GVN/preserve-memoryssa.ll index b78aba2..282dbc0 100644 --- a/llvm/test/Transforms/GVN/preserve-memoryssa.ll +++ b/llvm/test/Transforms/GVN/preserve-memoryssa.ll @@ -97,7 +97,7 @@ for.body.i22: define void @test_assume_false_to_store_undef_1(i32* %ptr) { ; CHECK-LABEL: @test_assume_false_to_store_undef_1( ; CHECK-NEXT: store i32 10, i32* [[PTR:%.*]], align 4 -; CHECK-NEXT: store i8 undef, i8* null, align 1 +; CHECK-NEXT: store i8 poison, i8* null, align 1 ; CHECK-NEXT: call void @f() ; CHECK-NEXT: ret void ; @@ -113,7 +113,7 @@ define i32 @test_assume_false_to_store_undef_2(i32* %ptr, i32* %ptr.2) { ; CHECK-LABEL: @test_assume_false_to_store_undef_2( ; CHECK-NEXT: store i32 10, i32* [[PTR:%.*]], align 4 ; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[PTR_2:%.*]], align 4 -; CHECK-NEXT: store i8 undef, i8* null, align 1 +; CHECK-NEXT: store i8 poison, i8* null, align 1 ; CHECK-NEXT: call void @f() ; CHECK-NEXT: ret i32 [[LV]] ; @@ -130,7 +130,7 @@ define i32 @test_assume_false_to_store_undef_3(i32* %ptr, i32* %ptr.2) { ; CHECK-LABEL: @test_assume_false_to_store_undef_3( ; CHECK-NEXT: store i32 10, i32* [[PTR:%.*]], align 4 ; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[PTR_2:%.*]], align 4 -; CHECK-NEXT: store i8 undef, i8* null, align 1 +; CHECK-NEXT: store i8 poison, i8* null, align 1 ; CHECK-NEXT: ret i32 [[LV]] ; store i32 10, i32* %ptr -- 2.7.4