mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 19:12:56 +02:00
[CodeGenPrepare] avoid crashing on non-canonical/degenerate code
The test is reduced from an example in the post-commit thread for: rL354746 http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20190304/632396.html While we must avoid dying here, the real question should be: Why is non-canonical and/or degenerate code making it to CGP when using the new pass manager? llvm-svn: 355345
This commit is contained in:
parent
dd5c010238
commit
8f1017e9ee
@ -1203,6 +1203,11 @@ static bool matchUAddWithOverflowConstantEdgeCases(CmpInst *Cmp,
|
||||
// Add = add A, 1; Cmp = icmp eq A,-1 (overflow if A is max val)
|
||||
// Add = add A,-1; Cmp = icmp ne A, 0 (overflow if A is non-zero)
|
||||
Value *A = Cmp->getOperand(0), *B = Cmp->getOperand(1);
|
||||
|
||||
// We are not expecting non-canonical/degenerate code. Just bail out.
|
||||
if (isa<Constant>(A))
|
||||
return false;
|
||||
|
||||
ICmpInst::Predicate Pred = Cmp->getPredicate();
|
||||
if (Pred == ICmpInst::ICMP_EQ && match(B, m_AllOnes()))
|
||||
B = ConstantInt::get(B->getType(), 1);
|
||||
|
@ -430,6 +430,31 @@ end:
|
||||
ret i1 %ov
|
||||
}
|
||||
|
||||
; Verify that crazy/non-canonical code does not crash.
|
||||
|
||||
define void @bar() {
|
||||
; CHECK-LABEL: @bar(
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 1, -1
|
||||
; CHECK-NEXT: [[FROMBOOL:%.*]] = zext i1 [[CMP]] to i8
|
||||
; CHECK-NEXT: unreachable
|
||||
;
|
||||
%cmp = icmp eq i64 1, -1
|
||||
%frombool = zext i1 %cmp to i8
|
||||
unreachable
|
||||
}
|
||||
|
||||
define void @foo() {
|
||||
; CHECK-LABEL: @foo(
|
||||
; CHECK-NEXT: [[SUB:%.*]] = add nsw i64 1, 1
|
||||
; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[SUB]] to i32
|
||||
; CHECK-NEXT: unreachable
|
||||
;
|
||||
%sub = add nsw i64 1, 1
|
||||
%conv = trunc i64 %sub to i32
|
||||
unreachable
|
||||
}
|
||||
|
||||
|
||||
; Check that every instruction inserted by -codegenprepare has a debug location.
|
||||
; DEBUG: CheckModuleDebugify: PASS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user