1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[ConstraintElimination] Skip pointer casts.

We should be able to look through pointer casts that do not impact the
value.
This commit is contained in:
Florian Hahn 2021-02-02 17:01:40 +00:00
parent 74267eec45
commit 513c51ee8a
2 changed files with 11 additions and 10 deletions

View File

@ -139,8 +139,8 @@ getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
if (Pred != CmpInst::ICMP_ULE && Pred != CmpInst::ICMP_ULT)
return {};
auto ADec = decompose(Op0);
auto BDec = decompose(Op1);
auto ADec = decompose(Op0->stripPointerCasts());
auto BDec = decompose(Op1->stripPointerCasts());
// Skip if decomposing either of the values failed.
if (ADec.empty() || BDec.empty())
return {};

View File

@ -2,6 +2,7 @@
; RUN: opt -constraint-elimination -S %s | FileCheck %s
define i1 @bitcast_and_cmp(i32* readonly %src, i32* readnone %min, i32* readnone %max) {
;
; CHECK-LABEL: @bitcast_and_cmp(
; CHECK-NEXT: check.0.min:
; CHECK-NEXT: [[SRC_C:%.*]] = bitcast i32* [[SRC:%.*]] to i8*
@ -18,19 +19,19 @@ define i1 @bitcast_and_cmp(i32* readonly %src, i32* readnone %min, i32* readnone
; CHECK: checks:
; CHECK-NEXT: [[C_3_MIN:%.*]] = icmp ult i32* [[GEP_3]], [[MIN]]
; CHECK-NEXT: [[C_3_MAX:%.*]] = icmp ult i32* [[GEP_3]], [[MAX]]
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_3_MIN]], [[C_3_MAX]]
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 false, [[C_3_MAX]]
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 1
; CHECK-NEXT: [[C_1_MIN:%.*]] = icmp ult i32* [[GEP_1]], [[MIN]]
; CHECK-NEXT: [[C_1_MAX:%.*]] = icmp ult i32* [[GEP_1]], [[MAX]]
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[C_1_MIN]], [[C_1_MAX]]
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 false, true
; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 2
; CHECK-NEXT: [[C_2_MIN:%.*]] = icmp ult i32* [[GEP_2]], [[MIN]]
; CHECK-NEXT: [[C_2_MAX:%.*]] = icmp ult i32* [[GEP_2]], [[MAX]]
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[C_2_MIN]], [[C_2_MAX]]
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 false, true
; CHECK-NEXT: [[GEP_4:%.*]] = getelementptr inbounds i32, i32* [[SRC]], i64 4
; CHECK-NEXT: [[C_4_MIN:%.*]] = icmp ult i32* [[GEP_2]], [[MIN]]
; CHECK-NEXT: [[C_4_MAX:%.*]] = icmp ult i32* [[GEP_2]], [[MAX]]
; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[C_4_MIN]], [[C_4_MAX]]
; CHECK-NEXT: [[C_4_MIN:%.*]] = icmp ult i32* [[GEP_4]], [[MIN]]
; CHECK-NEXT: [[C_4_MAX:%.*]] = icmp ult i32* [[GEP_4]], [[MAX]]
; CHECK-NEXT: [[RES_4:%.*]] = xor i1 false, [[C_4_MAX]]
; CHECK-NEXT: [[RES_5:%.*]] = xor i1 [[RES_1]], [[RES_2]]
; CHECK-NEXT: [[RES_6:%.*]] = xor i1 [[RES_5]], [[RES_3]]
; CHECK-NEXT: [[RES_7:%.*]] = xor i1 [[RES_6]], [[RES_4]]
@ -68,8 +69,8 @@ checks:
%res.3 = xor i1 %c.2.min, %c.2.max
%gep.4 = getelementptr inbounds i32, i32* %src, i64 4
%c.4.min = icmp ult i32* %gep.2, %min
%c.4.max = icmp ult i32* %gep.2, %max
%c.4.min = icmp ult i32* %gep.4, %min
%c.4.max = icmp ult i32* %gep.4, %max
%res.4 = xor i1 %c.4.min, %c.4.max
%res.5 = xor i1 %res.1, %res.2