Skip to content

Commit b2a829a

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f45f4ae7834e' from llvm.org/main into next
2 parents d7a8bf7 + f45f4ae commit b2a829a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

mlir/lib/Transforms/Utils/FoldUtils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,14 @@ bool OperationFolder::insertKnownConstant(Operation *op, Attribute constValue) {
154154
// already at the front of the block, or the previous operation is already a
155155
// constant we unique'd (i.e. one we inserted), then we don't need to do
156156
// anything. Otherwise, we move the constant to the insertion block.
157+
// The location info is erased if the constant is moved to a different block.
157158
Block *insertBlock = &insertRegion->front();
158-
if (opBlock != insertBlock || (&insertBlock->front() != op &&
159-
!isFolderOwnedConstant(op->getPrevNode()))) {
159+
if (opBlock != insertBlock) {
160160
op->moveBefore(&insertBlock->front());
161161
op->setLoc(erasedFoldedLocation);
162+
} else if (&insertBlock->front() != op &&
163+
!isFolderOwnedConstant(op->getPrevNode())) {
164+
op->moveBefore(&insertBlock->front());
162165
}
163166

164167
folderConstOp = op;

mlir/test/Transforms/canonicalize-debuginfo.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func.func @merge_constants() -> (index, index, index, index) {
1515

1616
// CHECK-LABEL: func @simple_hoist
1717
func.func @simple_hoist(%arg0: memref<8xi32>) -> i32 {
18-
// CHECK: arith.constant 88 : i32 loc(#[[UnknownLoc:.*]])
18+
// CHECK: arith.constant 88 : i32 loc(#[[ConstLoc2:.*]])
1919
// CHECK: arith.constant 42 : i32 loc(#[[ConstLoc0:.*]])
2020
// CHECK: arith.constant 0 : index loc(#[[ConstLoc1:.*]])
2121
%0 = arith.constant 42 : i32 loc("simple_hoist":0:0)
@@ -26,9 +26,9 @@ func.func @simple_hoist(%arg0: memref<8xi32>) -> i32 {
2626

2727
return %2 : i32
2828
}
29-
// CHECK-DAG: #[[UnknownLoc]] = loc(unknown)
3029
// CHECK-DAG: #[[ConstLoc0]] = loc("simple_hoist":0:0)
3130
// CHECK-DAG: #[[ConstLoc1]] = loc("simple_hoist":1:0)
31+
// CHECK-DAG: #[[ConstLoc2]] = loc("simple_hoist":2:0)
3232

3333
// -----
3434

0 commit comments

Comments
 (0)