Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e88ca40

Browse files
author
git apple-llvm automerger
committed
Merge commit 'e3d114ceb867' from llvm.org/main into next
2 parents 58fc8cb + e3d114c commit e88ca40

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

llvm/include/llvm/Transforms/Scalar/Reassociate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class ReassociatePass : public PassInfoMixin<ReassociatePass> {
133133
SmallVectorImpl<reassociate::Factor> &Factors);
134134
Value *OptimizeMul(BinaryOperator *I,
135135
SmallVectorImpl<reassociate::ValueEntry> &Ops);
136-
Value *RemoveFactorFromExpression(Value *V, Value *Factor);
136+
Value *RemoveFactorFromExpression(Value *V, Value *Factor, DebugLoc DL);
137137
void EraseInst(Instruction *I);
138138
void RecursivelyEraseDeadInsts(Instruction *I, OrderedSet &Insts);
139139
void OptimizeInst(Instruction *I);

llvm/lib/Transforms/Scalar/Reassociate.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,10 @@ static Value *EmitAddTreeOfValues(Instruction *I,
11001100
/// If V is an expression tree that is a multiplication sequence,
11011101
/// and if this sequence contains a multiply by Factor,
11021102
/// remove Factor from the tree and return the new tree.
1103-
Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor) {
1103+
/// If new instructions are inserted to generate this tree, DL should be used
1104+
/// as the DebugLoc for these instructions.
1105+
Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor,
1106+
DebugLoc DL) {
11041107
BinaryOperator *BO = isReassociableOp(V, Instruction::Mul, Instruction::FMul);
11051108
if (!BO)
11061109
return nullptr;
@@ -1164,8 +1167,10 @@ Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor) {
11641167
V = BO;
11651168
}
11661169

1167-
if (NeedsNegate)
1170+
if (NeedsNegate) {
11681171
V = CreateNeg(V, "neg", InsertPt, BO);
1172+
cast<Instruction>(V)->setDebugLoc(DL);
1173+
}
11691174

11701175
return V;
11711176
}
@@ -1666,7 +1671,8 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
16661671
if (!BOp)
16671672
continue;
16681673

1669-
if (Value *V = RemoveFactorFromExpression(Ops[i].Op, MaxOccVal)) {
1674+
if (Value *V = RemoveFactorFromExpression(Ops[i].Op, MaxOccVal,
1675+
I->getDebugLoc())) {
16701676
// The factorized operand may occur several times. Convert them all in
16711677
// one fell swoop.
16721678
for (unsigned j = Ops.size(); j != i;) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -p=reassociate < %s | FileCheck %s
3+
4+
;; When reassociating the expression below, we reduce it to using a single
5+
;; multiply and as part of that we generate a sub that negates one of the
6+
;; original terms; this negation "neg" should use the original expression's
7+
;; source location.
8+
9+
define i32 @foo(i64 %0, i64 %1) {
10+
; CHECK-LABEL: define i32 @foo(
11+
; CHECK-SAME: i64 [[TMP0:%.*]], i64 [[TMP1:%.*]]) {
12+
; CHECK-NEXT: [[ENTRY:.*:]]
13+
; CHECK-NEXT: [[NEG:%.*]] = sub i64 0, [[TMP1]], !dbg [[DBG3:![0-9]+]]
14+
; CHECK-NEXT: [[REASS_ADD:%.*]] = add i64 [[NEG]], [[TMP0]]
15+
; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i64 [[REASS_ADD]], 1000, !dbg [[DBG3]]
16+
; CHECK-NEXT: store i64 [[REASS_MUL]], ptr null, align 8
17+
; CHECK-NEXT: ret i32 0
18+
;
19+
entry:
20+
%mul1026 = mul i64 %0, 1000
21+
%add1028 = or i64 %mul1026, 0
22+
%mul1029 = mul i64 %1, 1000
23+
%sub1032 = sub i64 %add1028, %mul1029, !dbg !4
24+
store i64 %sub1032, ptr null, align 8
25+
ret i32 0
26+
}
27+
28+
!llvm.dbg.cu = !{!0}
29+
!llvm.module.flags = !{!3}
30+
31+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 20.0.0git")
32+
!1 = !DIFile(filename: "test.c", directory: "/tmp")
33+
!2 = !{}
34+
!3 = !{i32 2, !"Debug Info Version", i32 3}
35+
!4 = !DILocation(line: 10, column: 53, scope: !5)
36+
!5 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 550, type: !7, scopeLine: 557, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
37+
!7 = distinct !DISubroutineType(types: !2)
38+
;.
39+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
40+
; CHECK: [[META1]] = !DIFile(filename: "test.c", directory: {{.*}})
41+
; CHECK: [[DBG3]] = !DILocation(line: 10, column: 53, scope: [[META4:![0-9]+]])
42+
; CHECK: [[META4]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 550, type: [[META5:![0-9]+]], scopeLine: 557, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META6:![0-9]+]])
43+
; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META6]])
44+
; CHECK: [[META6]] = !{}
45+
;.

0 commit comments

Comments
 (0)