[llvm] 4491f0b - [IR] Remove unnecessary bitcast from CreateMalloc()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 18 05:58:24 PDT 2023
Author: Nikita Popov
Date: 2023-09-18T14:58:16+02:00
New Revision: 4491f0b969c04c93e8db397d51c6986e9371a49b
URL: https://github.com/llvm/llvm-project/commit/4491f0b969c04c93e8db397d51c6986e9371a49b
DIFF: https://github.com/llvm/llvm-project/commit/4491f0b969c04c93e8db397d51c6986e9371a49b.diff
LOG: [IR] Remove unnecessary bitcast from CreateMalloc()
This bitcast is no longer necessary with opaque pointers. This
results in some annoying variable name changes in tests.
Added:
Modified:
llvm/lib/IR/Instructions.cpp
llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
llvm/test/CodeGen/WebAssembly/lower-wasm-ehsjlj.ll
llvm/test/CodeGen/WebAssembly/lower-wasm-sjlj.ll
polly/test/CodeGen/MemAccess/create_arrays_heap.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index e995293dcd47d9f..72d3c85e5c9fe55 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -868,24 +868,12 @@ static Instruction *createMalloc(Instruction *InsertBefore,
if (!MallocFunc)
// prototype malloc as "void *malloc(size_t)"
MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
- PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
CallInst *MCall = nullptr;
- Instruction *Result = nullptr;
if (InsertBefore) {
- MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall",
+ MCall = CallInst::Create(MallocFunc, AllocSize, OpB, Name,
InsertBefore);
- Result = MCall;
- if (Result->getType() != AllocPtrType)
- // Create a cast instruction to convert to the right type...
- Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore);
} else {
- MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall");
- Result = MCall;
- if (Result->getType() != AllocPtrType) {
- MCall->insertInto(InsertAtEnd, InsertAtEnd->end());
- // Create a cast instruction to convert to the right type...
- Result = new BitCastInst(MCall, AllocPtrType, Name);
- }
+ MCall = CallInst::Create(MallocFunc, AllocSize, OpB, Name);
}
MCall->setTailCall();
if (Function *F = dyn_cast<Function>(MallocFunc.getCallee())) {
@@ -895,7 +883,7 @@ static Instruction *createMalloc(Instruction *InsertBefore,
}
assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
- return Result;
+ return MCall;
}
/// CreateMalloc - Generate the IR for a call to malloc:
diff --git a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
index b571de47273940c..7115b01ed1618e9 100644
--- a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
+++ b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
@@ -110,8 +110,8 @@ entry:
call void @foo()
ret void
; CHECK: call.em.longjmp:
-; CHECK-NEXT: %threw.phi = phi [[PTR]] [ %__THREW__.val, %if.then1 ], [ %__THREW__.val3, %if.then14 ]
-; CHECK-NEXT: %threwvalue.phi = phi i32 [ %__threwValue.val, %if.then1 ], [ %__threwValue.val7, %if.then14 ]
+; CHECK-NEXT: %threw.phi = phi [[PTR]] [ %__THREW__.val, %if.then1 ], [ %__THREW__.val4, %if.then15 ]
+; CHECK-NEXT: %threwvalue.phi = phi i32 [ %__threwValue.val, %if.then1 ], [ %__threwValue.val8, %if.then15 ]
; CHECK-NEXT: tail call void @free(ptr %[[SETJMP_TABLE1]])
; CHECK-NEXT: call void @emscripten_longjmp([[PTR]] %threw.phi, i32 %threwvalue.phi)
; CHECK-NEXT: unreachable
@@ -158,9 +158,9 @@ if.then: ; preds = %entry
; CHECK-NEXT: %[[SETJMP_TABLE_SIZE1:.*]] = call i32 @getTempRet0()
; CHECK: if.then.split:
-; CHECK: %[[VAR1:.*]] = phi i32 [ %[[VAR2:.*]], %if.end2 ], [ %[[VAR0]], %if.then ]
-; CHECK: %[[SETJMP_TABLE_SIZE2:.*]] = phi i32 [ %[[SETJMP_TABLE_SIZE1]], %if.then ], [ %[[SETJMP_TABLE_SIZE3:.*]], %if.end2 ]
-; CHECK: %[[SETJMP_TABLE2:.*]] = phi ptr [ %[[SETJMP_TABLE1]], %if.then ], [ %[[SETJMP_TABLE3:.*]], %if.end2 ]
+; CHECK: %[[VAR1:.*]] = phi i32 [ %[[VAR2:.*]], %if.end3 ], [ %[[VAR0]], %if.then ]
+; CHECK: %[[SETJMP_TABLE_SIZE2:.*]] = phi i32 [ %[[SETJMP_TABLE_SIZE1]], %if.then ], [ %[[SETJMP_TABLE_SIZE3:.*]], %if.end3 ]
+; CHECK: %[[SETJMP_TABLE2:.*]] = phi ptr [ %[[SETJMP_TABLE1]], %if.then ], [ %[[SETJMP_TABLE3:.*]], %if.end3 ]
; CHECK: store i32 %[[VAR1]], ptr @global_var, align 4
if.end: ; preds = %if.then, %entry
@@ -169,7 +169,7 @@ if.end: ; preds = %if.then, %entry
; CHECK: if.end:
; CHECK: %[[VAR2]] = phi i32 [ %[[VAR1]], %if.then.split ], [ undef, %entry.split ]
; CHECK: %[[SETJMP_TABLE_SIZE3]] = phi i32 [ %[[SETJMP_TABLE_SIZE2]], %if.then.split ], [ %[[SETJMP_TABLE_SIZE0]], %entry.split ]
-; CHECK: %[[SETJMP_TABLE3]] = phi ptr [ %[[SETJMP_TABLE2]], %if.then.split ], [ %malloccall, %entry.split ]
+; CHECK: %[[SETJMP_TABLE3]] = phi ptr [ %[[SETJMP_TABLE2]], %if.then.split ], [ %setjmpTable, %entry.split ]
}
; Test a case when a function only calls other functions that are neither setjmp nor longjmp
diff --git a/llvm/test/CodeGen/WebAssembly/lower-wasm-ehsjlj.ll b/llvm/test/CodeGen/WebAssembly/lower-wasm-ehsjlj.ll
index 03e19c011c76932..25471eb50081b39 100644
--- a/llvm/test/CodeGen/WebAssembly/lower-wasm-ehsjlj.ll
+++ b/llvm/test/CodeGen/WebAssembly/lower-wasm-ehsjlj.ll
@@ -108,7 +108,7 @@ catch: ; preds = %catch.start
call void @__cxa_end_catch() [ "funclet"(token %2) ]
catchret from %2 to label %catchret.dest
; CHECK: catch: ; preds = %catch.start
-; CHECK-NEXT: %exn = load ptr, ptr %exn.slot14, align 4
+; CHECK-NEXT: %exn = load ptr, ptr %exn.slot15, align 4
; CHECK-NEXT: %5 = call ptr @__cxa_begin_catch(ptr %exn) #7 [ "funclet"(token %2) ]
; CHECK-NEXT: invoke void @__cxa_end_catch() [ "funclet"(token %2) ]
; CHECK-NEXT: to label %.noexc unwind label %catch.dispatch.longjmp
@@ -230,9 +230,9 @@ terminate: ; preds = %ehcleanup
; change to an invoke whose unwind destination is determined by its parent
; chain.
; CHECK-NEXT: invoke void @terminate() {{.*}} [ "funclet"(token [[T2]]) ]
-; CHECK-NEXT: to label %.noexc3 unwind label %catch.dispatch5
+; CHECK-NEXT: to label %[[NOEXC:.*]] unwind label %catch.dispatch5
-; CHECK: .noexc3:
+; CHECK: [[NOEXC]]:
; CHECK-NEXT: unreachable
; CHECK: catch.dispatch.longjmp:
@@ -265,7 +265,7 @@ ehcleanup: ; preds = %entry
; (cleanuppad), whose parent is 'none', so we should unwind directly to
; %catch.dispatch.longjmp.
%call2 = call noundef ptr @_ZN4TempD2Ev(ptr noundef %t) #2 [ "funclet"(token %0) ]
-; CHECK: %call23 = invoke {{.*}} ptr @_ZN4TempD2Ev(ptr
+; CHECK: %call13 = invoke {{.*}} ptr @_ZN4TempD2Ev(ptr
; CHECK-NEXT: to label {{.*}} unwind label %catch.dispatch.longjmp
cleanupret from %0 unwind to caller
}
diff --git a/llvm/test/CodeGen/WebAssembly/lower-wasm-sjlj.ll b/llvm/test/CodeGen/WebAssembly/lower-wasm-sjlj.ll
index e303770d6775bfe..b8d2230fac9f5bb 100644
--- a/llvm/test/CodeGen/WebAssembly/lower-wasm-sjlj.ll
+++ b/llvm/test/CodeGen/WebAssembly/lower-wasm-sjlj.ll
@@ -25,16 +25,16 @@ entry:
unreachable
; CHECK: entry:
-; CHECK-NEXT: %malloccall = tail call ptr @malloc([[PTR]] 40)
-; CHECK-NEXT: store i32 0, ptr %malloccall, align 4
+; CHECK-NEXT: %setjmpTable = tail call ptr @malloc([[PTR]] 40)
+; CHECK-NEXT: store i32 0, ptr %setjmpTable, align 4
; CHECK-NEXT: %setjmpTableSize = add i32 4, 0
; CHECK-NEXT: br label %setjmp.dispatch
; CHECK: setjmp.dispatch:
-; CHECK-NEXT: %val8 = phi i32 [ %val, %if.end ], [ undef, %entry ]
-; CHECK-NEXT: %buf7 = phi ptr [ %buf6, %if.end ], [ undef, %entry ]
-; CHECK-NEXT: %setjmpTableSize4 = phi i32 [ %setjmpTableSize5, %if.end ], [ %setjmpTableSize, %entry ]
-; CHECK-NEXT: %setjmpTable2 = phi ptr [ %setjmpTable3, %if.end ], [ %malloccall, %entry ]
+; CHECK-NEXT: %[[VAL2:.*]] = phi i32 [ %val, %if.end ], [ undef, %entry ]
+; CHECK-NEXT: %[[BUF:.*]] = phi ptr [ %[[BUF2:.*]], %if.end ], [ undef, %entry ]
+; CHECK-NEXT: %[[SETJMPTABLESIZE2:.*]] = phi i32 [ %[[SETJMPTABLESIZE3:.*]], %if.end ], [ %setjmpTableSize, %entry ]
+; CHECK-NEXT: %[[SETJMPTABLE2:.*]] = phi ptr [ %[[SETJMPTABLE3:.*]], %if.end ], [ %setjmpTable, %entry ]
; CHECK-NEXT: %label.phi = phi i32 [ %label, %if.end ], [ -1, %entry ]
; CHECK-NEXT: switch i32 %label.phi, label %entry.split [
; CHECK-NEXT: i32 1, label %entry.split.split
@@ -42,16 +42,16 @@ entry:
; CHECK: entry.split:
; CHECK-NEXT: %buf = alloca [1 x %struct.__jmp_buf_tag], align 16
-; CHECK-NEXT: %setjmpTable = call ptr @saveSetjmp(ptr %buf, i32 1, ptr %setjmpTable2, i32 %setjmpTableSize4)
-; CHECK-NEXT: %setjmpTableSize1 = call i32 @getTempRet0()
+; CHECK-NEXT: %[[SETJMPTABLE4:.*]] = call ptr @saveSetjmp(ptr %buf, i32 1, ptr %[[SETJMPTABLE2]], i32 %[[SETJMPTABLESIZE2]])
+; CHECK-NEXT: %[[SETJMPTABLESIZE4:.*]] = call i32 @getTempRet0()
; CHECK-NEXT: br label %entry.split.split
; CHECK: entry.split.split:
-; CHECK-NEXT: %buf6 = phi ptr [ %buf7, %setjmp.dispatch ], [ %buf, %entry.split ]
-; CHECK-NEXT: %setjmpTableSize5 = phi i32 [ %setjmpTableSize1, %entry.split ], [ %setjmpTableSize4, %setjmp.dispatch ]
-; CHECK-NEXT: %setjmpTable3 = phi ptr [ %setjmpTable, %entry.split ], [ %setjmpTable2, %setjmp.dispatch ]
-; CHECK-NEXT: %setjmp.ret = phi i32 [ 0, %entry.split ], [ %val8, %setjmp.dispatch ]
-; CHECK-NEXT: invoke void @__wasm_longjmp(ptr %buf6, i32 1)
+; CHECK-NEXT: %[[BUF2]] = phi ptr [ %[[BUF]], %setjmp.dispatch ], [ %buf, %entry.split ]
+; CHECK-NEXT: %[[SETJMPTABLESIZE3]] = phi i32 [ %[[SETJMPTABLESIZE4]], %entry.split ], [ %[[SETJMPTABLESIZE2]], %setjmp.dispatch ]
+; CHECK-NEXT: %[[SETJMPTABLE3]] = phi ptr [ %[[SETJMPTABLE4]], %entry.split ], [ %[[SETJMPTABLE2]], %setjmp.dispatch ]
+; CHECK-NEXT: %setjmp.ret = phi i32 [ 0, %entry.split ], [ %[[VAL2]], %setjmp.dispatch ]
+; CHECK-NEXT: invoke void @__wasm_longjmp(ptr %[[BUF2]], i32 1)
; CHECK-NEXT: to label %.noexc unwind label %catch.dispatch.longjmp
; CHECK: .noexc:
@@ -68,12 +68,12 @@ entry:
; CHECK-NEXT: %env = load ptr, ptr %env_gep, align {{.*}}
; CHECK-NEXT: %val = load i32, ptr %val_gep, align 4
; CHECK-NEXT: %setjmp.id = load [[PTR]], ptr %env, align {{.*}}
-; CHECK-NEXT: %label = call i32 @testSetjmp([[PTR]] %setjmp.id, ptr %setjmpTable3, i32 %setjmpTableSize5) [ "funclet"(token %1) ]
+; CHECK-NEXT: %label = call i32 @testSetjmp([[PTR]] %setjmp.id, ptr %[[SETJMPTABLE3]], i32 %[[SETJMPTABLESIZE3]]) [ "funclet"(token %1) ]
; CHECK-NEXT: %2 = icmp eq i32 %label, 0
; CHECK-NEXT: br i1 %2, label %if.then, label %if.end
; CHECK: if.then:
-; CHECK-NEXT: tail call void @free(ptr %setjmpTable3) [ "funclet"(token %1) ]
+; CHECK-NEXT: tail call void @free(ptr %[[SETJMPTABLE3]]) [ "funclet"(token %1) ]
; CHECK-NEXT: call void @__wasm_longjmp(ptr %env, i32 %val) [ "funclet"(token %1) ]
; CHECK-NEXT: unreachable
diff --git a/polly/test/CodeGen/MemAccess/create_arrays_heap.ll b/polly/test/CodeGen/MemAccess/create_arrays_heap.ll
index ada9bd98d7617b2..d2554d24711dee9 100644
--- a/polly/test/CodeGen/MemAccess/create_arrays_heap.ll
+++ b/polly/test/CodeGen/MemAccess/create_arrays_heap.ll
@@ -31,21 +31,21 @@
; %E : size(E) = 270336*200000*8 = 432537600000 cast to double*
; %F : size(F) = 270336*8 = 2162688 cast to i64*
; CODEGEN: polly.start:
-; CODEGEN: %malloccall = tail call ptr @malloc(i64 2162688)
-; CODEGEN: %malloccall1 = tail call ptr @malloc(i64 432537600000)
-; CODEGEN: %malloccall2 = tail call ptr @malloc(i64 2162688)
+; CODEGEN: %D = tail call ptr @malloc(i64 2162688)
+; CODEGEN: %E = tail call ptr @malloc(i64 432537600000)
+; CODEGEN: %F = tail call ptr @malloc(i64 2162688)
;
; Check if there are the 3 expected malloc calls with the right parameters at polly.exiting.
; Cast to i8* before freeing because malloc give us a i8 and free is waiting for a i8*
; CODEGEN: polly.exiting:
-; CODEGEN: tail call void @free(ptr %malloccall)
-; CODEGEN: tail call void @free(ptr %malloccall1)
-; CODEGEN: tail call void @free(ptr %malloccall2)
+; CODEGEN: tail call void @free(ptr %D)
+; CODEGEN: tail call void @free(ptr %E)
+; CODEGEN: tail call void @free(ptr %F)
;
; Check if the new access for array E is present.
; CODEGEN: %polly.access.mul.{{.*}} = mul nsw i64 %polly.indvar, 200000
; CODEGEN: %polly.access.add.{{.*}} = add nsw i64 %polly.access.mul.{{.*}}, %
-; CODEGEN: %polly.access.{{.*}} = getelementptr double, ptr %malloccall1, i64 %polly.access.add.{{.*}}
+; CODEGEN: %polly.access.{{.*}} = getelementptr double, ptr %E, i64 %polly.access.add.{{.*}}
;
; ModuleID = 'create_arrays_heap.ll'
;
More information about the llvm-commits
mailing list