Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7579,16 +7579,23 @@ static bool isGuaranteedNotToBeUndefOrPoison(
if (isa<UndefValue>(C))
return !includesUndef(Kind);

if (isa<ConstantInt>(C) || isa<GlobalVariable>(C) || isa<ConstantFP>(V) ||
if (isa<ConstantInt>(C) || isa<GlobalVariable>(C) || isa<ConstantFP>(C) ||
isa<ConstantPointerNull>(C) || isa<Function>(C))
return true;

if (C->getType()->isVectorTy() && !isa<ConstantExpr>(C)) {
if (includesUndef(Kind) && C->containsUndefElement())
return false;
if (includesPoison(Kind) && C->containsPoisonElement())
return false;
return !C->containsConstantExpression();
if (C->getType()->isVectorTy()) {
if (isa<ConstantExpr>(C)) {
// Scalable vectors can use a ConstantExpr to build a splat.
if (Constant *SplatC = C->getSplatValue())
if (isa<ConstantInt>(SplatC) || isa<ConstantFP>(SplatC))
return true;
} else {
if (includesUndef(Kind) && C->containsUndefElement())
return false;
if (includesPoison(Kind) && C->containsPoisonElement())
return false;
return !C->containsConstantExpression();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/Attributor/nofpclass.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2665,7 +2665,7 @@ define [4 x float] @constant_aggregate_zero() {

define <vscale x 4 x float> @scalable_splat_pnorm() {
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
; CHECK-LABEL: define <vscale x 4 x float> @scalable_splat_pnorm
; CHECK-LABEL: define noundef <vscale x 4 x float> @scalable_splat_pnorm
; CHECK-SAME: () #[[ATTR3]] {
; CHECK-NEXT: ret <vscale x 4 x float> splat (float 1.000000e+00)
;
Expand Down
28 changes: 28 additions & 0 deletions llvm/test/Transforms/InstCombine/select-and-or.ll
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ define i1 @logical_or_implies(i32 %x) {
ret i1 %res
}

; Safe to convert to or due to poison implication.
define <vscale x 2 x i1> @logical_or_implies_scalablevec(<vscale x 2 x i32> %x) {
; CHECK-LABEL: @logical_or_implies_scalablevec(
; CHECK-NEXT: [[C1:%.*]] = icmp eq <vscale x 2 x i32> [[X:%.*]], zeroinitializer
; CHECK-NEXT: [[C2:%.*]] = icmp eq <vscale x 2 x i32> [[X]], splat (i32 42)
; CHECK-NEXT: [[RES:%.*]] = or <vscale x 2 x i1> [[C1]], [[C2]]
; CHECK-NEXT: ret <vscale x 2 x i1> [[RES]]
;
%c1 = icmp eq <vscale x 2 x i32> %x, zeroinitializer
%c2 = icmp eq <vscale x 2 x i32> %x, splat (i32 42)
%res = select <vscale x 2 x i1> %c1, <vscale x 2 x i1> splat (i1 true), <vscale x 2 x i1> %c2
ret <vscale x 2 x i1> %res
}

; Will fold after conversion to or.
define i1 @logical_or_implies_folds(i32 %x) {
; CHECK-LABEL: @logical_or_implies_folds(
Expand All @@ -129,6 +143,20 @@ define i1 @logical_and_implies(i32 %x) {
ret i1 %res
}

; Safe to convert to and due to poison implication.
define <vscale x 2 x i1> @logical_and_implies_scalablevec(<vscale x 2 x i32> %x) {
; CHECK-LABEL: @logical_and_implies_scalablevec(
; CHECK-NEXT: [[C1:%.*]] = icmp ne <vscale x 2 x i32> [[X:%.*]], zeroinitializer
; CHECK-NEXT: [[C2:%.*]] = icmp ne <vscale x 2 x i32> [[X]], splat (i32 42)
; CHECK-NEXT: [[RES:%.*]] = and <vscale x 2 x i1> [[C1]], [[C2]]
; CHECK-NEXT: ret <vscale x 2 x i1> [[RES]]
;
%c1 = icmp ne <vscale x 2 x i32> %x, zeroinitializer
%c2 = icmp ne <vscale x 2 x i32> %x, splat (i32 42)
%res = select <vscale x 2 x i1> %c1, <vscale x 2 x i1> %c2, <vscale x 2 x i1> zeroinitializer
ret <vscale x 2 x i1> %res
}

; Will fold after conversion to and.
define i1 @logical_and_implies_folds(i32 %x) {
; CHECK-LABEL: @logical_and_implies_folds(
Expand Down