Skip to content

Commit b76df59

Browse files
committed
Revert "Recommit "[SCCP] Do not replace deref'able ptr with un-deref'able one.""
Looks like there is still another remaining issue: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-msan/builds/22273/steps/build%20libcxx%2Fmsan/logs/stdio This reverts commit 86a20d9.
1 parent 86a20d9 commit b76df59

File tree

5 files changed

+5
-43
lines changed

5 files changed

+5
-43
lines changed

llvm/lib/Analysis/Loads.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,6 @@ bool llvm::canReplacePointersIfEqual(Value *A, Value *B, const DataLayout &DL,
510510
assert(Ty == B->getType() && Ty->isPointerTy() &&
511511
"values must have matching pointer types");
512512

513-
// Function pointers are not directly dereferenced using load/store
514-
// instructions. Allow any replacements for now.
515-
if (A->getType()->getPointerElementType()->isFunctionTy())
516-
return true;
517513
// NOTE: The checks in the function are incomplete and currently miss illegal
518514
// cases! The current implementation is a starting point and the
519515
// implementation should be made stricter over time.

llvm/lib/Transforms/Scalar/SCCP.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "llvm/Analysis/DomTreeUpdater.h"
3232
#include "llvm/Analysis/GlobalsModRef.h"
3333
#include "llvm/Analysis/InstructionSimplify.h"
34-
#include "llvm/Analysis/Loads.h"
3534
#include "llvm/Analysis/TargetLibraryInfo.h"
3635
#include "llvm/Analysis/ValueLattice.h"
3736
#include "llvm/Analysis/ValueLatticeUtils.h"
@@ -178,8 +177,6 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
178177
LLVMContext &Ctx;
179178

180179
public:
181-
const DataLayout &getDataLayout() const { return DL; }
182-
183180
void addAnalysis(Function &F, AnalysisResultsForFn A) {
184181
AnalysisResults.insert({&F, std::move(A)});
185182
}
@@ -1652,14 +1649,6 @@ static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) {
16521649
return false;
16531650
}
16541651

1655-
// Do not propagate equality of a un-dereferenceable pointer.
1656-
// FIXME: Currently this only treats pointers one past the last element
1657-
// for array types. Should probably be much stricter.
1658-
if (Const->getType()->isPointerTy() &&
1659-
!canReplacePointersIfEqual(V, Const, Solver.getDataLayout(),
1660-
dyn_cast<Instruction>(V)))
1661-
return false;
1662-
16631652
LLVM_DEBUG(dbgs() << " Constant: " << *Const << " = " << *V << '\n');
16641653

16651654
// Replaces all of the uses of a variable with uses of the constant.

llvm/test/Transforms/SCCP/apint-bigint2.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ define i101 @large_aggregate_2() {
5151
}
5252

5353
; CHECK-LABEL: @index_too_large
54-
; CHECK-NEXT: %ptr1 = getelementptr [6 x i101], [6 x i101]* @Y, i32 0, i32 -1
55-
; CHECK-NEXT: %ptr2 = getelementptr i101, i101* %ptr1, i101 9224497936761618431
56-
; CHECK-NEXT: store i101* %ptr2, i101** undef
57-
; CHECK-NEXT: ret void
54+
; CHECK-NEXT: store i101* getelementptr (i101, i101* getelementptr ([6 x i101], [6 x i101]* @Y, i32 0, i32 -1), i101 9224497936761618431), i101** undef
55+
; CHECK-NEXT: ret void
5856
define void @index_too_large() {
5957
%ptr1 = getelementptr [6 x i101], [6 x i101]* @Y, i32 0, i32 -1
6058
%ptr2 = getelementptr i101, i101* %ptr1, i101 9224497936761618431

llvm/test/Transforms/SCCP/indirectbr.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ BB1:
3131
define void @indbrtest2() {
3232
; CHECK-LABEL: @indbrtest2(
3333
; CHECK-NEXT: entry:
34-
; CHECK-NEXT: [[B:%.*]] = inttoptr i64 ptrtoint (i8* blockaddress(@indbrtest2, [[BB1:%.*]]) to i64) to i8*
35-
; CHECK-NEXT: [[C:%.*]] = bitcast i8* [[B]] to i8*
36-
; CHECK-NEXT: br label [[BB1]]
34+
; CHECK-NEXT: br label [[BB1:%.*]]
3735
; CHECK: BB1:
3836
; CHECK-NEXT: call void @BB1_f()
3937
; CHECK-NEXT: ret void

llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define i32 @eq_undereferenceable(i32* %p) {
1111
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[P:%.*]], getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
1212
; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
1313
; CHECK: if.then:
14-
; CHECK-NEXT: store i32 2, i32* [[P]], align 4
14+
; CHECK-NEXT: store i32 2, i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1), align 4
1515
; CHECK-NEXT: br label [[IF_END]]
1616
; CHECK: if.end:
1717
; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @y, i64 0, i64 0), align 4
@@ -65,7 +65,7 @@ define i1 @eq_undereferenceable_cmp_simp(i32* %p) {
6565
; CHECK-NEXT: [[CMP_0:%.*]] = icmp eq i32* [[P:%.*]], getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
6666
; CHECK-NEXT: br i1 [[CMP_0]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
6767
; CHECK: if.then:
68-
; CHECK-NEXT: store i32 2, i32* [[P]], align 4
68+
; CHECK-NEXT: store i32 2, i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1), align 4
6969
; CHECK-NEXT: ret i1 true
7070
; CHECK: if.end:
7171
; CHECK-NEXT: [[CMP_2:%.*]] = icmp eq i32* [[P]], getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
@@ -84,22 +84,3 @@ if.end: ; preds = %if.then, %entry
8484
%cmp.2 = icmp eq i32* %p, getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
8585
ret i1 %cmp.2
8686
}
87-
88-
89-
; Test cases with function pointers. Currently any replacements are allowed
90-
; for them.
91-
@FnGlobal1 = internal global void (i8*)* undef, align 8
92-
93-
define void (i8*)* @test_global_undef_fn_ptr() {
94-
%lv = load void (i8*)*, void (i8*)** @FnGlobal1, align 8
95-
ret void (i8*)* %lv
96-
}
97-
98-
declare void @foo(i8*)
99-
100-
@FnGlobal2 = internal global void (i8*)* @foo, align 8
101-
102-
define void (i8*)* @test_global_undef_fn_ptr2() {
103-
%lv = load void (i8*)*, void (i8*)** @FnGlobal2, align 8
104-
ret void (i8*)* %lv
105-
}

0 commit comments

Comments
 (0)