[llvm] b76df59 - Revert "Recommit "[SCCP] Do not replace deref'able ptr with un-deref'able one.""

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 01:19:19 PDT 2020


Author: Florian Hahn
Date: 2020-09-29T09:18:19+01:00
New Revision: b76df593eb660d1e4c9f1384a75b404ee5bcd06f

URL: https://github.com/llvm/llvm-project/commit/b76df593eb660d1e4c9f1384a75b404ee5bcd06f
DIFF: https://github.com/llvm/llvm-project/commit/b76df593eb660d1e4c9f1384a75b404ee5bcd06f.diff

LOG: 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 86a20d9e34f5a9989da72097f23f3b0a44157e73.

Added: 
    

Modified: 
    llvm/lib/Analysis/Loads.cpp
    llvm/lib/Transforms/Scalar/SCCP.cpp
    llvm/test/Transforms/SCCP/apint-bigint2.ll
    llvm/test/Transforms/SCCP/indirectbr.ll
    llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 5b9f46652382..d63f6b9b1964 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -510,10 +510,6 @@ bool llvm::canReplacePointersIfEqual(Value *A, Value *B, const DataLayout &DL,
   assert(Ty == B->getType() && Ty->isPointerTy() &&
          "values must have matching pointer types");
 
-  // Function pointers are not directly dereferenced using load/store
-  // instructions. Allow any replacements for now.
-  if (A->getType()->getPointerElementType()->isFunctionTy())
-    return true;
   // NOTE: The checks in the function are incomplete and currently miss illegal
   // cases! The current implementation is a starting point and the
   // implementation should be made stricter over time.

diff  --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index b73842ed6a12..33ab2907906e 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -31,7 +31,6 @@
 #include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/InstructionSimplify.h"
-#include "llvm/Analysis/Loads.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/ValueLattice.h"
 #include "llvm/Analysis/ValueLatticeUtils.h"
@@ -178,8 +177,6 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
   LLVMContext &Ctx;
 
 public:
-  const DataLayout &getDataLayout() const { return DL; }
-
   void addAnalysis(Function &F, AnalysisResultsForFn A) {
     AnalysisResults.insert({&F, std::move(A)});
   }
@@ -1652,14 +1649,6 @@ static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) {
     return false;
   }
 
-  // Do not propagate equality of a un-dereferenceable pointer.
-  // FIXME: Currently this only treats pointers one past the last element
-  // for array types. Should probably be much stricter.
-  if (Const->getType()->isPointerTy() &&
-      !canReplacePointersIfEqual(V, Const, Solver.getDataLayout(),
-                                 dyn_cast<Instruction>(V)))
-    return false;
-
   LLVM_DEBUG(dbgs() << "  Constant: " << *Const << " = " << *V << '\n');
 
   // Replaces all of the uses of a variable with uses of the constant.

diff  --git a/llvm/test/Transforms/SCCP/apint-bigint2.ll b/llvm/test/Transforms/SCCP/apint-bigint2.ll
index 7d1a9a68372c..8effa2181a4c 100644
--- a/llvm/test/Transforms/SCCP/apint-bigint2.ll
+++ b/llvm/test/Transforms/SCCP/apint-bigint2.ll
@@ -51,10 +51,8 @@ define i101 @large_aggregate_2() {
 }
 
 ; CHECK-LABEL: @index_too_large
-; CHECK-NEXT:    %ptr1 = getelementptr [6 x i101], [6 x i101]* @Y, i32 0, i32 -1
-; CHECK-NEXT:    %ptr2 = getelementptr i101, i101* %ptr1, i101 9224497936761618431
-; CHECK-NEXT:    store i101* %ptr2, i101** undef
-; CHECK-NEXT:    ret void
+; CHECK-NEXT: store i101* getelementptr (i101, i101* getelementptr ([6 x i101], [6 x i101]* @Y, i32 0, i32 -1), i101 9224497936761618431), i101** undef
+; CHECK-NEXT: ret void
 define void @index_too_large() {
   %ptr1 = getelementptr [6 x i101], [6 x i101]* @Y, i32 0, i32 -1
   %ptr2 = getelementptr i101, i101* %ptr1, i101 9224497936761618431

diff  --git a/llvm/test/Transforms/SCCP/indirectbr.ll b/llvm/test/Transforms/SCCP/indirectbr.ll
index 1a9ae8a128f1..6889282e3874 100644
--- a/llvm/test/Transforms/SCCP/indirectbr.ll
+++ b/llvm/test/Transforms/SCCP/indirectbr.ll
@@ -31,9 +31,7 @@ BB1:
 define void @indbrtest2() {
 ; CHECK-LABEL: @indbrtest2(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[B:%.*]] = inttoptr i64 ptrtoint (i8* blockaddress(@indbrtest2, [[BB1:%.*]]) to i64) to i8*
-; CHECK-NEXT:    [[C:%.*]] = bitcast i8* [[B]] to i8*
-; CHECK-NEXT:    br label [[BB1]]
+; CHECK-NEXT:    br label [[BB1:%.*]]
 ; CHECK:       BB1:
 ; CHECK-NEXT:    call void @BB1_f()
 ; CHECK-NEXT:    ret void

diff  --git a/llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll b/llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll
index 898da01b356f..5857ce2d30b7 100644
--- a/llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll
+++ b/llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll
@@ -11,7 +11,7 @@ define i32 @eq_undereferenceable(i32* %p) {
 ; 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)
 ; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
 ; CHECK:       if.then:
-; CHECK-NEXT:    store i32 2, i32* [[P]], align 4
+; 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
 ; CHECK-NEXT:    br label [[IF_END]]
 ; CHECK:       if.end:
 ; 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) {
 ; 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)
 ; CHECK-NEXT:    br i1 [[CMP_0]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
 ; CHECK:       if.then:
-; CHECK-NEXT:    store i32 2, i32* [[P]], align 4
+; 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
 ; CHECK-NEXT:    ret i1 true
 ; CHECK:       if.end:
 ; 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
   %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)
   ret i1 %cmp.2
 }
-
-
-; Test cases with function pointers. Currently any replacements are allowed
-; for them.
- at FnGlobal1 = internal global void (i8*)* undef, align 8
-
-define void (i8*)* @test_global_undef_fn_ptr() {
-  %lv = load void (i8*)*, void (i8*)** @FnGlobal1, align 8
-  ret void (i8*)* %lv
-}
-
-declare void @foo(i8*)
-
- at FnGlobal2 = internal global void (i8*)* @foo, align 8
-
-define void (i8*)* @test_global_undef_fn_ptr2() {
-  %lv = load void (i8*)*, void (i8*)** @FnGlobal2, align 8
-  ret void (i8*)* %lv
-}


        


More information about the llvm-commits mailing list