[llvm] 145aff6 - Clean up pointer casts etc after opaque pointers transition. NFC (#102631)

Bjorn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 12 04:29:34 PDT 2024


Author: Bjorn Pettersson
Date: 2024-08-12T13:28:53+02:00
New Revision: 145aff6d924714b625de1d83247583df2ab73763

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

LOG: Clean up pointer casts etc after opaque pointers transition. NFC (#102631)

Added: 
    

Modified: 
    llvm/examples/BrainF/BrainFDriver.cpp
    llvm/examples/ExceptionDemo/ExceptionDemo.cpp
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
    llvm/lib/Transforms/Scalar/NaryReassociate.cpp
    llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/examples/BrainF/BrainFDriver.cpp b/llvm/examples/BrainF/BrainFDriver.cpp
index 98fa735e1491f7..a42e67590533c9 100644
--- a/llvm/examples/BrainF/BrainFDriver.cpp
+++ b/llvm/examples/BrainF/BrainFDriver.cpp
@@ -72,7 +72,7 @@ void addMainFunction(Module *mod) {
   FunctionType *main_func_fty = FunctionType::get(
       Type::getInt32Ty(mod->getContext()),
       {Type::getInt32Ty(mod->getContext()),
-       Type::getInt8Ty(mod->getContext())->getPointerTo()->getPointerTo()},
+       PointerType::getUnqual(mod->getContext())},
       false);
   Function *main_func =
       Function::Create(main_func_fty, Function::ExternalLinkage, "main", mod);

diff  --git a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
index fdee76cb96146e..27acb9a155ecd8 100644
--- a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
+++ b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
@@ -1244,8 +1244,7 @@ static llvm::Function *createCatchWrappedInvokeFunction(
   llvm::Value *unwindExceptionClass =
       builder.CreateLoad(builder.CreateStructGEP(
           ourUnwindExceptionType,
-          builder.CreatePointerCast(unwindException,
-                                    ourUnwindExceptionType->getPointerTo()),
+          unwindException,
           0));
 
   // Branch to the externalExceptionBlock if the exception is foreign or
@@ -1277,10 +1276,8 @@ static llvm::Function *createCatchWrappedInvokeFunction(
   // (OurException instance).
   //
   // Note: ourBaseFromUnwindOffset is usually negative
-  llvm::Value *typeInfoThrown = builder.CreatePointerCast(
-                                  builder.CreateConstGEP1_64(unwindException,
-                                                       ourBaseFromUnwindOffset),
-                                  ourExceptionType->getPointerTo());
+  llvm::Value *typeInfoThrown = builder.CreateConstGEP1_64(unwindException,
+                                                      ourBaseFromUnwindOffset));
 
   // Retrieve thrown exception type info type
   //

diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index b64fe83959eb18..7ab2f2c13def87 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2453,8 +2453,8 @@ bool AsmPrinter::doFinalization(Module &M) {
       auto SymbolName = "swift_async_extendedFramePointerFlags";
       auto Global = M.getGlobalVariable(SymbolName);
       if (!Global) {
-        auto Int8PtrTy = PointerType::getUnqual(M.getContext());
-        Global = new GlobalVariable(M, Int8PtrTy, false,
+        auto PtrTy = PointerType::getUnqual(M.getContext());
+        Global = new GlobalVariable(M, PtrTy, false,
                                     GlobalValue::ExternalWeakLinkage, nullptr,
                                     SymbolName);
         OutStreamer->emitSymbolAttribute(getSymbol(Global), MCSA_WeakReference);

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 2db05c669145b9..2bba83b5cde3c7 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -4567,7 +4567,7 @@ Instruction *InstCombinerImpl::foldNot(BinaryOperator &I) {
     Type *SextTy = cast<BitCastOperator>(NotOp)->getSrcTy();
     Value *NotX = Builder.CreateNot(X);
     Value *Sext = Builder.CreateSExt(NotX, SextTy);
-    return CastInst::CreateBitOrPointerCast(Sext, Ty);
+    return new BitCastInst(Sext, Ty);
   }
 
   if (auto *NotOpI = dyn_cast<Instruction>(NotOp))

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 6bcff6f9d49efd..b86f27168303a1 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -2386,7 +2386,7 @@ static Instruction *foldSelectCmpBitcasts(SelectInst &Sel,
   } else {
     return nullptr;
   }
-  return CastInst::CreateBitOrPointerCast(NewSel, Sel.getType());
+  return new BitCastInst(NewSel, Sel.getType());
 }
 
 /// Try to eliminate select instructions that test the returned flag of cmpxchg

diff  --git a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
index c00c71fcb0b43a..39720672c202d7 100644
--- a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
@@ -421,10 +421,7 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
     return nullptr;
 
   IRBuilder<> Builder(GEP);
-  // Candidate does not necessarily have the same pointer type as GEP. Use
-  // bitcast or pointer cast to make sure they have the same type, so that the
-  // later RAUW doesn't complain.
-  Candidate = Builder.CreateBitOrPointerCast(Candidate, GEP->getType());
+  // Candidate should have the same pointer type as GEP.
   assert(Candidate->getType() == GEP->getType());
 
   // NewGEP = (char *)Candidate + RHS * sizeof(IndexedType)

diff  --git a/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp b/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
index 32870d9fb37378..4d6111cc257c3b 100644
--- a/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
+++ b/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
@@ -73,9 +73,8 @@ TEST_F(ScalarEvolutionExpanderTest, ExpandPtrTypeSCEV) {
   // expansion when the value in ValueOffsetPair is a ptr and the offset
   // is not divisible by the elem type size of value.
   auto *I8Ty = Type::getInt8Ty(Context);
-  auto *I8PtrTy = PointerType::get(Context, 0);
+  auto *PtrTy = PointerType::get(Context, 0);
   auto *I32Ty = Type::getInt32Ty(Context);
-  auto *I32PtrTy = PointerType::get(Context, 0);
   FunctionType *FTy =
       FunctionType::get(Type::getVoidTy(Context), std::vector<Type *>(), false);
   Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M);
@@ -87,13 +86,11 @@ TEST_F(ScalarEvolutionExpanderTest, ExpandPtrTypeSCEV) {
 
   // loop:                            ; preds = %loop, %entry
   //   %alloca = alloca i32
-  //   %gep0 = getelementptr i32, i32* %alloca, i32 1
-  //   %bitcast1 = bitcast i32* %gep0 to i8*
-  //   %gep1 = getelementptr i8, i8* %bitcast1, i32 1
-  //   %gep2 = getelementptr i8, i8* undef, i32 1
-  //   %cmp = icmp ult i8* undef, %bitcast1
-  //   %select = select i1 %cmp, i8* %gep1, i8* %gep2
-  //   %bitcast2 = bitcast i8* %select to i32*
+  //   %gep0 = getelementptr i32, ptr %alloca, i32 1
+  //   %gep1 = getelementptr i8, ptr %gep0, i32 1
+  //   %gep2 = getelementptr i8, ptr undef, i32 1
+  //   %cmp = icmp ult ptr undef, %gep0
+  //   %select = select i1 %cmp, ptr %gep1, ptr %gep2
   //   br i1 undef, label %loop, label %exit
 
   const DataLayout &DL = F->getDataLayout();
@@ -102,24 +99,20 @@ TEST_F(ScalarEvolutionExpanderTest, ExpandPtrTypeSCEV) {
   AllocaInst *Alloca = new AllocaInst(I32Ty, DL.getAllocaAddrSpace(), "alloca",
                                       Br->getIterator());
   ConstantInt *Ci32 = ConstantInt::get(Context, APInt(32, 1));
+  UndefValue *UndefPtr = UndefValue::get(PtrTy);
   GetElementPtrInst *Gep0 =
       GetElementPtrInst::Create(I32Ty, Alloca, Ci32, "gep0", Br->getIterator());
-  CastInst *CastA = CastInst::CreateBitOrPointerCast(Gep0, I8PtrTy, "bitcast1",
-                                                     Br->getIterator());
   GetElementPtrInst *Gep1 =
-      GetElementPtrInst::Create(I8Ty, CastA, Ci32, "gep1", Br->getIterator());
+      GetElementPtrInst::Create(I8Ty, Gep0, Ci32, "gep1", Br->getIterator());
   GetElementPtrInst *Gep2 = GetElementPtrInst::Create(
-      I8Ty, UndefValue::get(I8PtrTy), Ci32, "gep2", Br->getIterator());
+      I8Ty, UndefPtr, Ci32, "gep2", Br->getIterator());
   CmpInst *Cmp = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_ULT,
-                                 UndefValue::get(I8PtrTy), CastA, "cmp",
-                                 Br->getIterator());
-  SelectInst *Sel =
+                                 UndefPtr, Gep0, "cmp", Br->getIterator());
+  SelectInst *Select =
       SelectInst::Create(Cmp, Gep1, Gep2, "select", Br->getIterator());
-  CastInst *CastB = CastInst::CreateBitOrPointerCast(Sel, I32PtrTy, "bitcast2",
-                                                     Br->getIterator());
 
   ScalarEvolution SE = buildSE(*F);
-  const SCEV *S = SE.getSCEV(CastB);
+  const SCEV *S = SE.getSCEV(Select);
   EXPECT_TRUE(isa<SCEVUnknown>(S));
 }
 


        


More information about the llvm-commits mailing list