Skip to content

Commit 81ddd17

Browse files
committed
Skip anything that is not an instruction from current basic block
1 parent a5b5b9a commit 81ddd17

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6100,11 +6100,11 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
61006100

61016101
if (!ResultIndex) {
61026102
auto PtrInst = dyn_cast<Instruction>(ResultPtr);
6103-
// Here we know that we have just a pointer without any offsets. If
6104-
// this pointer comes from a different from the current basic block we
6105-
// need to know how to recreate it in another basic block.
6106-
// Currently we don't support recreation of any of instruction.
6107-
if (PtrInst && PtrInst->getParent() != MemoryInst->getParent())
6103+
// We know that we have a pointer without any offsets. If this pointer
6104+
// originates from a different basic block than the current one, we
6105+
// must be able to recreate it in the current basic block.
6106+
// We do not support the recreation of any instructions yet.
6107+
if (!PtrInst || PtrInst->getParent() != MemoryInst->getParent())
61086108
return Modified;
61096109
SunkAddr = ResultPtr;
61106110
} else {

llvm/test/Transforms/CodeGenPrepare/X86/sink-addr-recreate.ll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ define void @addr_from_arg(ptr %ptr, i1 %p) {
5353
; CHECK: [[BODY_1]]:
5454
; CHECK-NEXT: [[SUNKADDR:%.*]] = bitcast ptr [[PTR]] to ptr
5555
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[SUNKADDR]], align 4
56-
; CHECK-NEXT: [[UNUSED:%.*]] = load <4 x i32>, ptr [[PTR]], align 4
57-
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[PTR]], align 4
56+
; CHECK-NEXT: [[TMP0:%.*]] = bitcast ptr [[PTR]] to ptr
57+
; CHECK-NEXT: [[UNUSED:%.*]] = load <4 x i32>, ptr [[TMP0]], align 4
58+
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[TMP0]], align 4
5859
; CHECK-NEXT: ret void
5960
;
6061
entry:
@@ -84,8 +85,8 @@ define void @addr_from_global(i1 %p) {
8485
; CHECK: [[BODY_1]]:
8586
; CHECK-NEXT: [[GEP1:%.*]] = bitcast ptr @globalptr to ptr
8687
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[GEP1]], align 4
87-
; CHECK-NEXT: [[UNUSED:%.*]] = load <4 x i32>, ptr @globalptr, align 4
88-
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr @globalptr, align 4
88+
; CHECK-NEXT: [[UNUSED:%.*]] = load <4 x i32>, ptr [[GEP1]], align 4
89+
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[GEP1]], align 4
8990
; CHECK-NEXT: ret void
9091
;
9192
entry:

0 commit comments

Comments
 (0)