2019-07-23 06:08:55 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2019-07-23 20:42:41 +08:00
|
|
|
; RUN: opt < %s -simplifycfg -S | FileCheck %s --check-prefixes=ALL,DEFAULT,FALLBACK0
|
|
|
|
; RUN: opt < %s -simplifycfg -phi-node-folding-threshold=2 -S | FileCheck %s --check-prefixes=ALL,DEFAULT,FALLBACK1
|
|
|
|
; RUN: opt < %s -simplifycfg -phi-node-folding-threshold=3 -S | FileCheck %s --check-prefixes=ALL,COSTLY
|
2019-07-23 06:08:55 +08:00
|
|
|
|
|
|
|
; This is checking that the multiplication does overflow, with a leftover
|
|
|
|
; guard against division-by-zero that was needed before InstCombine
|
|
|
|
; produced llvm.umul.with.overflow.
|
|
|
|
|
|
|
|
define i1 @will_overflow(i64 %size, i64 %nmemb) {
|
2019-07-23 20:42:41 +08:00
|
|
|
; ALL-LABEL: @will_overflow(
|
|
|
|
; ALL-NEXT: entry:
|
|
|
|
; ALL-NEXT: [[CMP:%.*]] = icmp eq i64 [[SIZE:%.*]], 0
|
|
|
|
; ALL-NEXT: [[UMUL:%.*]] = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 [[SIZE]], i64 [[NMEMB:%.*]])
|
|
|
|
; ALL-NEXT: [[UMUL_OV:%.*]] = extractvalue { i64, i1 } [[UMUL]], 1
|
|
|
|
; ALL-NEXT: [[UMUL_NOT_OV:%.*]] = xor i1 [[UMUL_OV]], true
|
[SimplifyCFG] FoldTwoEntryPHINode(): don't bailout on i1 PHI's if we can hoist a 'not' from incoming values
Summary:
As it can be seen in the tests in D65143/D65144, even though we have formed an '@llvm.umul.with.overflow'
and got rid of potential for division-by-zero, the control flow remains, we still have that branch.
We have this condition:
```
// Don't fold i1 branches on PHIs which contain binary operators
// These can often be turned into switches and other things.
if (PN->getType()->isIntegerTy(1) &&
(isa<BinaryOperator>(PN->getIncomingValue(0)) ||
isa<BinaryOperator>(PN->getIncomingValue(1)) ||
isa<BinaryOperator>(IfCond)))
return false;
```
which was added back in rL121764 to help with `select` formation i think?
That check prevents us to flatten the CFG here, even though we know
we no longer need that guard and will be able to drop everything
but the '@llvm.umul.with.overflow' + `not`.
As it can be seen from tests, we end here because the `not` is being
sinked into the PHI's incoming values by InstCombine,
so we can't workaround this by hoisting it to after PHI.
Thus i suggest that we relax that check to not bailout if we'd get to hoist the `not`.
Reviewers: craig.topper, spatel, fhahn, nikic
Reviewed By: spatel
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65147
llvm-svn: 370349
2019-08-29 20:47:34 +08:00
|
|
|
; ALL-NEXT: [[TMP0:%.*]] = select i1 [[CMP]], i1 true, i1 [[UMUL_NOT_OV]]
|
2019-07-23 20:42:41 +08:00
|
|
|
; ALL-NEXT: ret i1 [[TMP0]]
|
2019-07-23 06:08:55 +08:00
|
|
|
;
|
|
|
|
entry:
|
|
|
|
%cmp = icmp eq i64 %size, 0
|
|
|
|
br i1 %cmp, label %land.end, label %land.rhs
|
|
|
|
|
|
|
|
land.rhs: ; preds = %entry
|
|
|
|
%umul = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %size, i64 %nmemb)
|
|
|
|
%umul.ov = extractvalue { i64, i1 } %umul, 1
|
|
|
|
%umul.not.ov = xor i1 %umul.ov, true
|
|
|
|
br label %land.end
|
|
|
|
|
|
|
|
land.end: ; preds = %land.rhs, %entry
|
|
|
|
%0 = phi i1 [ true, %entry ], [ %umul.not.ov, %land.rhs ]
|
|
|
|
ret i1 %0
|
|
|
|
}
|
|
|
|
|
|
|
|
; Function Attrs: nounwind readnone speculatable
|
|
|
|
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0
|