mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-15 07:59:57 +00:00
[ValueTracking] Improve isKnownNonZero for PHI of non-zero constants
It is clear that a PHI is a non-zero if all incoming values are non-zero constants. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259370 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0a9644c134
commit
d9e550023c
@ -2074,6 +2074,12 @@ bool isKnownNonZero(Value *V, unsigned Depth, const Query &Q) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if all incoming values are non-zero constant.
|
||||
bool AllNonZeroConstants = all_of(PN->operands(), [](Value *V) {
|
||||
return isa<ConstantInt>(V) && !cast<ConstantInt>(V)->isZeroValue();
|
||||
});
|
||||
if (AllNonZeroConstants)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!BitWidth) return false;
|
||||
|
@ -760,3 +760,27 @@ epilog:
|
||||
; CHECK-NEXT: ret i1 %[[RES]]
|
||||
}
|
||||
|
||||
; CHECK-LABEL: phi_allnonzeroconstant
|
||||
; CHECK-NOT: phi i32
|
||||
; CHECK: ret i1 false
|
||||
define i1 @phi_allnonzeroconstant(i1 %c, i32 %a, i32 %b) {
|
||||
entry:
|
||||
br i1 %c, label %if.then, label %if.else
|
||||
|
||||
if.then: ; preds = %entry
|
||||
br label %if.end
|
||||
|
||||
if.else: ; preds = %entry
|
||||
call void @dummy()
|
||||
|
||||
br label %if.end
|
||||
|
||||
if.end: ; preds = %if.else, %if.then
|
||||
%x.0 = phi i32 [ 1, %if.then ], [ 2, %if.else ]
|
||||
%or = or i32 %x.0, %a
|
||||
%cmp1 = icmp eq i32 %or, 0
|
||||
ret i1 %cmp1
|
||||
}
|
||||
|
||||
declare void @dummy()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user