1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[SCCP] Do not mark unknown loads as overdefined.

For tracked globals that are unknown after solving, we expect all
non-store uses to be replaced.

This is a follow-up to f8045b250d80, which removed forcedconstant.

We should not mark unknown loads as overdefined, as they either load
from an unknown pointer or an undef global. Restore the original logic
for loads.
This commit is contained in:
Florian Hahn 2020-02-20 19:46:29 +01:00
parent 82be9993cd
commit 65ce9e19e8
5 changed files with 26 additions and 7 deletions

View File

@ -1501,6 +1501,13 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
if (TrackedRetVals.count(F))
continue;
if (isa<LoadInst>(I)) {
// A load here means one of two things: a load of undef from a global,
// a load from an unknown pointer. Either way, having it return undef
// is okay.
continue;
}
markOverdefined(&I);
return true;
}

View File

@ -11,8 +11,7 @@ define void @fn2(i32* %P) {
; CHECK: for.cond1:
; CHECK-NEXT: br i1 false, label [[IF_END]], label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* null, align 4
; CHECK-NEXT: [[CALL:%.*]] = call i32 @fn1(i32 [[TMP0]])
; CHECK-NEXT: [[CALL:%.*]] = call i32 @fn1(i32 undef)
; CHECK-NEXT: store i32 [[CALL]], i32* [[P]]
; CHECK-NEXT: br label [[FOR_COND1:%.*]]
;
@ -34,8 +33,8 @@ define internal i32 @fn1(i32 %p1) {
; CHECK-LABEL: define {{[^@]+}}@fn1
; CHECK-SAME: (i32 [[P1:%.*]])
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[P1]], 0
; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 [[P1]], i32 [[P1]]
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 undef, 0
; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 undef, i32 undef
; CHECK-NEXT: ret i32 [[COND]]
;
entry:

View File

@ -18,8 +18,7 @@ define i101 @array() {
}
; CHECK-LABEL: @large_aggregate
; CHECK-NEXT: %B = load i101, i101* undef
; CHECK-NEXT: %D = and i101 %B, 1
; CHECK-NEXT: %D = and i101 undef, 1
; CHECK-NEXT: %DD = or i101 %D, 1
; CHECK-NEXT: %G = getelementptr i101, i101* getelementptr inbounds ([6 x i101], [6 x i101]* @Y, i32 0, i32 5), i101 %DD
; CHECK-NEXT: %L3 = load i101, i101* %G

View File

@ -2,6 +2,7 @@
; RUN: opt < %s -data-layout="e-p:32:32" -debugify -sccp -S | FileCheck %s
; RUN: opt < %s -data-layout="E-p:32:32" -debugify -sccp -S | FileCheck %s
; RUN: opt < %s -data-layout="E-p:32:32" -debugify -ipsccp -S | FileCheck %s
@X = constant i32 42 ; <i32*> [#uses=1]
@Y = constant [2 x { i32, float }] [ { i32, float } { i32 12, float 1.000000e+00 }, { i32, float } { i32 37, float 0x3FF3B2FEC0000000 } ] ; <[2 x { i32, float }]*> [#uses=2]
@ -43,4 +44,3 @@ define i8 @test4() {
%B = load i8, i8* %A
ret i8 %B
}

View File

@ -0,0 +1,14 @@
; RUN: opt < %s -data-layout="E-p:32:32" -ipsccp -S | FileCheck %s
@j = internal global i32 undef, align 4
; Make sure we do not mark loads from undef as overdefined.
define i32 @test5(i32 %b) {
; CHECK-LABEL: define i32 @test5(i32 %b)
; CHECK-NEXT: %add = add nsw i32 undef, %b
; CHECK-NEXT: ret i32 %add
;
%l = load i32, i32* @j, align 4
%add = add nsw i32 %l, %b
ret i32 %add
}