llvm.org GIT mirror llvm / e9b0c81
[SCCP] Can't go from overdefined to constant The fix for PR23999 made us mark loads of null as producing the constant undef which upsets the lattice. Instead, keep the load as "undefined". This fixes PR26044. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257087 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 3 years ago
2 changed file(s) with 34 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
10461046 // global, we can replace the load with the loaded constant value!
10471047 void SCCPSolver::visitLoadInst(LoadInst &I) {
10481048 // If this load is of a struct, just mark the result overdefined.
1049 if (I.getType()->isStructTy())
1049 if (I.getType()->isStructTy() || I.getType()->isMMXTy())
10501050 return markAnythingOverdefined(&I);
10511051
10521052 LatticeVal PtrVal = getValueState(I.getOperand(0));
10601060
10611061 Constant *Ptr = PtrVal.getConstant();
10621062
1063 // load null -> null
1063 // load null is undefined.
10641064 if (isa(Ptr) && I.getPointerAddressSpace() == 0)
1065 return markConstant(IV, &I, UndefValue::get(I.getType()));
1065 return;
10661066
10671067 // Transform load (constant global) into the value loaded.
10681068 if (GlobalVariable *GV = dyn_cast(Ptr)) {
0 ; RUN: opt < %s -S -ipsccp | FileCheck %s
1 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2 target triple = "x86_64-unknown-linux-gnu"
3
4 define void @fn2() {
5 entry:
6 br label %if.end
7
8 for.cond1: ; preds = %if.end, %for.end
9 br i1 undef, label %if.end, label %if.end
10
11 if.end: ; preds = %lbl, %for.cond1
12 %e.2 = phi i32* [ undef, %entry ], [ null, %for.cond1 ], [ null, %for.cond1 ]
13 %0 = load i32, i32* %e.2, align 4
14 %call = call i32 @fn1(i32 %0)
15 br label %for.cond1
16 }
17
18 define internal i32 @fn1(i32 %p1) {
19 entry:
20 %tobool = icmp ne i32 %p1, 0
21 %cond = select i1 %tobool, i32 %p1, i32 %p1
22 ret i32 %cond
23 }
24
25 ; CHECK-LABEL: define void @fn2(
26 ; CHECK: call i32 @fn1(i32 undef)
27
28 ; CHECK-LABEL: define internal i32 @fn1(
29 ; CHECK:%[[COND:.*]] = select i1 undef, i32 undef, i32 undef
30 ; CHECK: ret i32 %[[COND]]