Skip to content
This repository was archived by the owner on Dec 20, 2019. It is now read-only.

Commit 1368f40

Browse files
committed
Merging r312509:
------------------------------------------------------------------------ r312509 | dannyb | 2017-09-04 19:17:42 -0700 (Mon, 04 Sep 2017) | 1 line NewGVN: Fix PR 34452 by passing instruction all the way down when we do aggregate value simplification ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@319952 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ddfb999 commit 1368f40

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ class NewGVN {
586586
private:
587587
// Expression handling.
588588
const Expression *createExpression(Instruction *) const;
589-
const Expression *createBinaryExpression(unsigned, Type *, Value *,
590-
Value *) const;
589+
const Expression *createBinaryExpression(unsigned, Type *, Value *, Value *,
590+
Instruction *) const;
591591
PHIExpression *createPHIExpression(Instruction *, bool &HasBackEdge,
592592
bool &OriginalOpsConstant) const;
593593
const DeadExpression *createDeadExpression() const;
@@ -902,8 +902,8 @@ bool NewGVN::setBasicExpressionInfo(Instruction *I, BasicExpression *E) const {
902902
}
903903

904904
const Expression *NewGVN::createBinaryExpression(unsigned Opcode, Type *T,
905-
Value *Arg1,
906-
Value *Arg2) const {
905+
Value *Arg1, Value *Arg2,
906+
Instruction *I) const {
907907
auto *E = new (ExpressionAllocator) BasicExpression(2);
908908

909909
E->setType(T);
@@ -921,7 +921,7 @@ const Expression *NewGVN::createBinaryExpression(unsigned Opcode, Type *T,
921921
E->op_push_back(lookupOperandLeader(Arg2));
922922

923923
Value *V = SimplifyBinOp(Opcode, E->getOperand(0), E->getOperand(1), SQ);
924-
if (const Expression *SimplifiedE = checkSimplificationResults(E, nullptr, V))
924+
if (const Expression *SimplifiedE = checkSimplificationResults(E, I, V))
925925
return SimplifiedE;
926926
return E;
927927
}
@@ -1699,8 +1699,9 @@ NewGVN::performSymbolicAggrValueEvaluation(Instruction *I) const {
16991699
// expression.
17001700
assert(II->getNumArgOperands() == 2 &&
17011701
"Expect two args for recognised intrinsics.");
1702-
return createBinaryExpression(
1703-
Opcode, EI->getType(), II->getArgOperand(0), II->getArgOperand(1));
1702+
return createBinaryExpression(Opcode, EI->getType(),
1703+
II->getArgOperand(0),
1704+
II->getArgOperand(1), I);
17041705
}
17051706
}
17061707
}
@@ -1933,6 +1934,7 @@ void NewGVN::touchAndErase(Map &M, const KeyType &Key) {
19331934
}
19341935

19351936
void NewGVN::addAdditionalUsers(Value *To, Value *User) const {
1937+
assert(User && To != User);
19361938
if (isa<Instruction>(To))
19371939
AdditionalUsers[To].insert(User);
19381940
}

test/Transforms/NewGVN/pr34452.ll

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -newgvn -S < %s | FileCheck %s
3+
;; Ensure we don't crash when simplifying aggregate value expressions
4+
source_filename = "bugpoint-output-09f7a24.bc"
5+
6+
@WHOLELINE = external local_unnamed_addr global i32, align 4
7+
8+
; Function Attrs: nounwind uwtable
9+
define void @sgrep() local_unnamed_addr #0 {
10+
; CHECK-LABEL: @sgrep(
11+
; CHECK-NEXT: entry:
12+
; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* @WHOLELINE, align 4, !tbaa !1
13+
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TMP0]], 0
14+
; CHECK-NEXT: [[DOT:%.*]] = select i1 [[TOBOOL]], i32 2048, i32 2047
15+
; CHECK-NEXT: br label [[WHILE_BODY_US:%.*]]
16+
; CHECK: while.body.us:
17+
; CHECK-NEXT: [[START_1230_US:%.*]] = phi i32 [ [[DOT]], [[ENTRY:%.*]] ], [ 0, [[WHILE_BODY_US]] ]
18+
; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[START_1230_US]] to i64
19+
; CHECK-NEXT: [[TMP2:%.*]] = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 0, i64 [[TMP1]])
20+
; CHECK-NEXT: br label [[WHILE_BODY_US]]
21+
;
22+
entry:
23+
%0 = load i32, i32* @WHOLELINE, align 4, !tbaa !1
24+
%tobool = icmp eq i32 %0, 0
25+
%. = select i1 %tobool, i32 2048, i32 2047
26+
br label %while.body.us
27+
28+
while.body.us: ; preds = %while.body.us, %entry
29+
%start.1230.us = phi i32 [ %., %entry ], [ 0, %while.body.us ]
30+
%1 = sext i32 %start.1230.us to i64
31+
%2 = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 0, i64 %1)
32+
%.res302 = extractvalue { i64, i1 } %2, 0
33+
%3 = icmp sge i64 undef, %.res302
34+
br label %while.body.us
35+
}
36+
37+
; Function Attrs: nounwind readnone speculatable
38+
declare { i64, i1 } @llvm.sadd.with.overflow.i64(i64, i64) #1
39+
40+
attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "polly-optimized" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
41+
attributes #1 = { nounwind readnone speculatable }
42+
43+
!llvm.ident = !{!0}
44+
45+
!0 = !{!"clang version 6.0.0 (trunk 311664) (llvm/trunk 311666)"}
46+
!1 = !{!2, !2, i64 0}
47+
!2 = !{!"int", !3, i64 0}
48+
!3 = !{!"omnipotent char", !4, i64 0}
49+
!4 = !{!"Simple C/C++ TBAA"}

0 commit comments

Comments
 (0)