[llvm] r203574 - Fix crash in PRE.
Erik Verbruggen
erikjv at me.com
Tue Mar 11 08:07:33 PDT 2014
Author: erikjv
Date: Tue Mar 11 10:07:32 2014
New Revision: 203574
URL: http://llvm.org/viewvc/llvm-project?rev=203574&view=rev
Log:
Fix crash in PRE.
After r203553 overflow intrinsics and their non-intrinsic (normal)
instruction get hashed to the same value. This patch prevents PRE from
moving an instruction into a predecessor block, and trying to add a phi
node that gets two different types (the intrinsic result and the
non-intrinsic result), resulting in a failing assert.
Modified:
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
llvm/trunk/test/Transforms/GVN/overflow.ll
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=203574&r1=203573&r2=203574&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Tue Mar 11 10:07:32 2014
@@ -2550,6 +2550,8 @@ bool GVN::performPRE(Function &F) {
predMap.push_back(std::make_pair(static_cast<Value *>(0), P));
PREPred = P;
++NumWithout;
+ } else if (predV->getType() != CurInst->getType()) {
+ continue;
} else if (predV == CurInst) {
/* CurInst dominates this predecessor. */
NumWithout = 2;
Modified: llvm/trunk/test/Transforms/GVN/overflow.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/overflow.ll?rev=203574&r1=203573&r2=203574&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/overflow.ll (original)
+++ llvm/trunk/test/Transforms/GVN/overflow.ll Tue Mar 11 10:07:32 2014
@@ -39,5 +39,29 @@ if.end:
; CHECK: ret i32 %sadd3.repl
}
+; Check if PRE does not crash
+define i32 @pre(i32 %a, i32 %b) nounwind ssp uwtable {
+entry:
+ %cmp = icmp sgt i32 %a, 42
+ br i1 %cmp, label %if.then, label %if.end3
+if.then: ; preds = %entry
+ %add = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
+ %add1 = extractvalue {i32, i1} %add, 0
+ %o = extractvalue {i32, i1} %add, 1
+ %o32 = zext i1 %o to i32
+ %add32 = add i32 %add1, %o32
+ %cmp1 = icmp sgt i32 %add1, 42
+ br i1 %cmp1, label %if.then2, label %if.end3
+
+if.then2: ; preds = %if.then
+ call void @abort() noreturn
+ unreachable
+
+if.end3: ; preds = %if.end, %entry
+ %add4 = add i32 %a, %b
+ ret i32 %add4
+}
+
+declare void @abort() noreturn
declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone
More information about the llvm-commits
mailing list