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

Reland r301880(!): "[InstSimplify] Handle selects of GEPs with 0 offset"

I was reminded today that this patch got reverted in r301885. I can no
longer reproduce the failure that caused the revert locally (...almost
one year later), and the patch applied pretty cleanly, so I guess we'll
see if the bots still get angry about it.

The original breakage was InstSimplify complaining (in "assertion
failed" form) about getting passed some crazy IR when running `ninja
check-sanitizer`. I'm unable to find traces of what, exactly, said crazy
IR was. I suppose we'll find out pretty soon if that's still the case.
:)

Original commit:

  Author: gbiv
  Date: Mon May  1 18:12:08 2017
  New Revision: 301880

  URL: http://llvm.org/viewvc/llvm-project?rev=301880&view=rev
  Log:
  [InstSimplify] Handle selects of GEPs with 0 offset

  In particular (since it wouldn't fit nicely in the summary):
  (select (icmp eq V 0) P (getelementptr P V)) -> (getelementptr P V)

  Differential Revision: https://reviews.llvm.org/D31435

llvm-svn: 330667
This commit is contained in:
George Burgess IV 2018-04-24 00:25:01 +00:00
parent 0d55a7bb36
commit 4f77a99095
2 changed files with 32 additions and 0 deletions

View File

@ -62,6 +62,8 @@ static Value *SimplifyOrInst(Value *, Value *, const SimplifyQuery &, unsigned);
static Value *SimplifyXorInst(Value *, Value *, const SimplifyQuery &, unsigned);
static Value *SimplifyCastInst(unsigned, Value *, Type *,
const SimplifyQuery &, unsigned);
static Value *SimplifyGEPInst(Type *, ArrayRef<Value *>, const SimplifyQuery &,
unsigned);
/// For a boolean type or a vector of boolean type, return false or a vector
/// with every element false.
@ -3528,6 +3530,17 @@ static const Value *SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
}
}
// Same for GEPs.
if (auto *GEP = dyn_cast<GetElementPtrInst>(I)) {
if (MaxRecurse) {
SmallVector<Value *, 8> NewOps(GEP->getNumOperands());
transform(GEP->operands(), NewOps.begin(),
[&](Value *V) { return V == Op ? RepOp : V; });
return SimplifyGEPInst(GEP->getSourceElementType(), NewOps, Q,
MaxRecurse - 1);
}
}
// TODO: We could hand off more cases to instsimplify here.
// If all operands are constant after substituting Op for RepOp then we can

View File

@ -545,3 +545,22 @@ define i8 @do_not_assume_sel_cond(i1 %cond, i8 %x, i8 %y) {
ret i8 %sel
}
define i32* @select_icmp_eq_0_gep_operand(i32* %base, i64 %n) {
; CHECK-LABEL: @select_icmp_eq_0_gep_operand(
; CHECK-NEXT: [[GEP:%.*]] = getelementptr
; CHECK-NEXT: ret i32* [[GEP]]
%cond = icmp eq i64 %n, 0
%gep = getelementptr i32, i32* %base, i64 %n
%r = select i1 %cond, i32* %base, i32* %gep
ret i32* %r
}
define i32* @select_icmp_ne_0_gep_operand(i32* %base, i64 %n) {
; CHECK-LABEL: @select_icmp_ne_0_gep_operand(
; CHECK-NEXT: [[GEP:%.*]] = getelementptr
; CHECK-NEXT: ret i32* [[GEP]]
%cond = icmp ne i64 %n, 0
%gep = getelementptr i32, i32* %base, i64 %n
%r = select i1 %cond, i32* %gep, i32* %base
ret i32* %r
}