Skip to content

Commit

Permalink
[ARM] Allow bitcasts in ARMCodeGenPrepare
Browse files Browse the repository at this point in the history
Allow bitcasts in the use-def chains, treating them as sources.

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

llvm-svn: 342032
  • Loading branch information
sparker-arm committed Sep 12, 2018
1 parent eaf4fd7 commit 569b245
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
9 changes: 4 additions & 5 deletions llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ static bool isSource(Value *V) {
return true;
else if (isa<LoadInst>(V))
return true;
else if (isa<BitCastInst>(V))
return true;
else if (auto *Call = dyn_cast<CallInst>(V))
return Call->hasRetAttr(Attribute::AttrKind::ZExt);
return false;
Expand Down Expand Up @@ -545,11 +547,8 @@ bool ARMCodeGenPrepare::isSupportedValue(Value *V) {
isa<LoadInst>(V))
return isSupportedType(V);

if (auto *Trunc = dyn_cast<TruncInst>(V))
return isSupportedType(Trunc->getOperand(0));

if (auto *ZExt = dyn_cast<ZExtInst>(V))
return isSupportedType(ZExt->getOperand(0));
if (isa<CastInst>(V) && !isa<SExtInst>(V))
return isSupportedType(cast<CastInst>(V)->getOperand(0));

// Special cases for calls as we need to check for zeroext
// TODO We should accept calls even if they don't have zeroext, as they can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,50 @@ cleanup:
ret i32 %retval.0
}

; CHECK-COMMON-LABEL: bitcast_i16
; CHECK-COMMON-NOT: uxt
define i16 @bitcast_i16(i16 zeroext %arg0, i16 zeroext %arg1) {
entry:
%cast = bitcast i16 12345 to i16
%add = add nuw i16 %arg0, 1
%cmp = icmp ule i16 %add, %cast
%res = select i1 %cmp, i16 %arg1, i16 32657
ret i16 %res
}

; CHECK-COMMON-LABEL: bitcast_i8
; CHECK-COMMON-NOT: uxt
define i8 @bitcast_i8(i8 zeroext %arg0, i8 zeroext %arg1) {
entry:
%cast = bitcast i8 127 to i8
%mul = shl nuw i8 %arg0, 1
%cmp = icmp uge i8 %mul, %arg1
%res = select i1 %cmp, i8 %cast, i8 128
ret i8 %res
}

; CHECK-COMMON-LABEL: bitcast_i16_minus
; CHECK-COMMON-NOT: uxt
define i16 @bitcast_i16_minus(i16 zeroext %arg0, i16 zeroext %arg1) {
entry:
%cast = bitcast i16 -12345 to i16
%xor = xor i16 %arg0, 7
%cmp = icmp eq i16 %xor, %arg1
%res = select i1 %cmp, i16 %cast, i16 32657
ret i16 %res
}

; CHECK-COMMON-LABEL: bitcast_i8_minus
; CHECK-COMMON-NOT: uxt
define i8 @bitcast_i8_minus(i8 zeroext %arg0, i8 zeroext %arg1) {
entry:
%cast = bitcast i8 -127 to i8
%and = and i8 %arg0, 3
%cmp = icmp ne i8 %and, %arg1
%res = select i1 %cmp, i8 %cast, i8 128
ret i8 %res
}

declare %class.x* @_ZNK2ae2afEv(%class.ae*) local_unnamed_addr
declare %class.v* @_ZN1x2acEv(%class.x*) local_unnamed_addr
declare i32 @dummy(i32, i32)
Expand Down

0 comments on commit 569b245

Please sign in to comment.