@@ -794,13 +794,14 @@ bool InstExpander::visitShl(BinaryOperator& BinOp) {
794
794
795
795
Value* Cond = nullptr ;
796
796
797
+ // Only LSB of ShAmt is used for shift
798
+ ShAmt = IRB->CreateAnd (ShAmt, 63 );
797
799
if (!isa<ConstantInt>(ShAmt)) {
798
800
// Create outer if-endif to handle the special case where `ShAmt` is zero.
799
801
// We have option to handle that with `((S >> (~ShAmt)) >> 1)`. However, as
800
802
// a zero `ShAmt` is a very rare case so that the outer branch should be
801
803
// uniform one in most cases.
802
- Value* NE = IRB->CreateICmpNE (IRB->CreateAnd (ShAmt, 63 ),
803
- Constant::getNullValue (ShAmt->getType ()));
804
+ Value* NE = IRB->CreateICmpNE (ShAmt, Constant::getNullValue (ShAmt->getType ()));
804
805
BasicBlock* JointBB = OldBB->splitBasicBlock (&BinOp);
805
806
ResLo = PHINode::Create (IRB->getInt32Ty (), 2 , " .shl.outer.merge.lo" , &BinOp);
806
807
ResHi = PHINode::Create (IRB->getInt32Ty (), 2 , " .shl.outer.merge.hi" , &BinOp);
@@ -816,10 +817,9 @@ bool InstExpander::visitShl(BinaryOperator& BinOp) {
816
817
// Create the inner branch.
817
818
IRB->SetInsertPoint (&(*TrueBB->begin ()));
818
819
819
- Cond = IRB->CreateICmpEQ (IRB->CreateAnd (ShAmt, 32 ),
820
- Constant::getNullValue (ShAmt->getType ()));
820
+ Cond = IRB->CreateICmpULT (ShAmt, IRB->getInt32 (32 ));
821
821
// Prepare to generate branches to handle the case where `ShAmt` is less
822
- // than 32 or otherwise.
822
+ // than 32 (true branch) or otherwise (false branch) .
823
823
BasicBlock* InnerJBB = TrueBB->splitBasicBlock (TrueJmp);
824
824
InnerResLo = PHINode::Create (IRB->getInt32Ty (), 2 , " .shl.merge.inner.lo" , TrueJmp);
825
825
InnerResHi = PHINode::Create (IRB->getInt32Ty (), 2 , " .shl.merge.inner.hi" , TrueJmp);
@@ -844,8 +844,7 @@ bool InstExpander::visitShl(BinaryOperator& BinOp) {
844
844
cast<PHINode>(ResHi)->addIncoming (InnerResHi, InnerJBB);
845
845
}
846
846
else
847
- Cond = IRB->CreateICmpEQ (IRB->CreateAnd (ShAmt, 32 ),
848
- Constant::getNullValue (ShAmt->getType ()));
847
+ Cond = IRB->CreateICmpULT (ShAmt, IRB->getInt32 (32 ));
849
848
850
849
if (Cond == IRB->getTrue () || InnerTBB) {
851
850
if (InnerTBB) IRB->SetInsertPoint (&(*InnerTBB->begin ()));
@@ -914,13 +913,14 @@ bool InstExpander::visitLShr(BinaryOperator& BinOp) {
914
913
915
914
Value* Cond = nullptr ;
916
915
916
+ // Only LSB of ShAmt is used for shift
917
+ ShAmt = IRB->CreateAnd (ShAmt, 63 );
917
918
if (!isa<ConstantInt>(ShAmt)) {
918
919
// Create outer if-endif to handle the special case where `ShAmt` is zero.
919
920
// We have option to handle that with `((S >> (~ShAmt)) >> 1)`. However, as
920
921
// a zero `ShAmt` is a very rare case so that the outer branch should be
921
922
// uniform one in most cases.
922
- Value* NE = IRB->CreateICmpNE (IRB->CreateAnd (ShAmt, 63 ),
923
- Constant::getNullValue (ShAmt->getType ()));
923
+ Value* NE = IRB->CreateICmpNE (ShAmt, Constant::getNullValue (ShAmt->getType ()));
924
924
BasicBlock* JointBB = OldBB->splitBasicBlock (&BinOp);
925
925
ResLo = PHINode::Create (IRB->getInt32Ty (), 2 , " .lshr.outer.merge.lo" , &BinOp);
926
926
ResHi = PHINode::Create (IRB->getInt32Ty (), 2 , " .lshr.outer.merge.hi" , &BinOp);
@@ -936,10 +936,9 @@ bool InstExpander::visitLShr(BinaryOperator& BinOp) {
936
936
// Create the inner branch.
937
937
IRB->SetInsertPoint (&(*TrueBB->begin ()));
938
938
939
- Cond = IRB->CreateICmpEQ (IRB->CreateAnd (ShAmt, 32 ),
940
- Constant::getNullValue (ShAmt->getType ()));
939
+ Cond = IRB->CreateICmpULT (ShAmt, IRB->getInt32 (32 ));
941
940
// Prepare to generate branches to handle the case where `ShAmt` is less
942
- // than 32 or otherwise.
941
+ // than 32 (true branch) or otherwise (false branch) .
943
942
BasicBlock* InnerJBB = TrueBB->splitBasicBlock (TrueJmp);
944
943
InnerResLo = PHINode::Create (IRB->getInt32Ty (), 2 , " .lshr.merge.inner.lo" , TrueJmp);
945
944
InnerResHi = PHINode::Create (IRB->getInt32Ty (), 2 , " .lshr.merge.inner.hi" , TrueJmp);
@@ -964,8 +963,7 @@ bool InstExpander::visitLShr(BinaryOperator& BinOp) {
964
963
cast<PHINode>(ResHi)->addIncoming (InnerResHi, InnerJBB);
965
964
}
966
965
else
967
- Cond = IRB->CreateICmpEQ (IRB->CreateAnd (ShAmt, 32 ),
968
- Constant::getNullValue (ShAmt->getType ()));
966
+ Cond = IRB->CreateICmpULT (ShAmt, IRB->getInt32 (32 ));
969
967
970
968
if (Cond == IRB->getTrue () || InnerTBB) {
971
969
if (InnerTBB) IRB->SetInsertPoint (&(*InnerTBB->begin ()));
@@ -1034,13 +1032,14 @@ bool InstExpander::visitAShr(BinaryOperator& BinOp) {
1034
1032
1035
1033
Value* Cond = nullptr ;
1036
1034
1035
+ // Only LSB of ShAmt is used for shift
1036
+ ShAmt = IRB->CreateAnd (ShAmt, 63 );
1037
1037
if (!isa<ConstantInt>(ShAmt)) {
1038
1038
// Create outer if-endif to handle the special case where `ShAmt` is zero.
1039
1039
// We have option to handle that with `((S >> (~ShAmt)) >> 1)`. However, as
1040
1040
// a zero `ShAmt` is a very rare case so that the outer branch should be
1041
1041
// uniform one in most cases.
1042
- Value* NE = IRB->CreateICmpNE (IRB->CreateAnd (ShAmt, 63 ),
1043
- Constant::getNullValue (ShAmt->getType ()));
1042
+ Value* NE = IRB->CreateICmpNE (ShAmt, Constant::getNullValue (ShAmt->getType ()));
1044
1043
BasicBlock* JointBB = OldBB->splitBasicBlock (&BinOp);
1045
1044
ResLo = PHINode::Create (IRB->getInt32Ty (), 2 , " .ashr.outer.merge.lo" , &BinOp);
1046
1045
ResHi = PHINode::Create (IRB->getInt32Ty (), 2 , " .ashr.outer.merge.hi" , &BinOp);
@@ -1056,8 +1055,7 @@ bool InstExpander::visitAShr(BinaryOperator& BinOp) {
1056
1055
// Create the inner branch.
1057
1056
IRB->SetInsertPoint (&(*TrueBB->begin ()));
1058
1057
1059
- Cond = IRB->CreateICmpEQ (IRB->CreateAnd (ShAmt, 32 ),
1060
- Constant::getNullValue (ShAmt->getType ()));
1058
+ Cond = IRB->CreateICmpULT (ShAmt, IRB->getInt32 (32 ));
1061
1059
// Prepare to generate branches to handle the case where `ShAmt` is less
1062
1060
// than 32 or otherwise.
1063
1061
BasicBlock* InnerJBB = TrueBB->splitBasicBlock (TrueJmp);
@@ -1084,8 +1082,7 @@ bool InstExpander::visitAShr(BinaryOperator& BinOp) {
1084
1082
cast<PHINode>(ResHi)->addIncoming (InnerResHi, InnerJBB);
1085
1083
}
1086
1084
else
1087
- Cond = IRB->CreateICmpEQ (IRB->CreateAnd (ShAmt, 32 ),
1088
- Constant::getNullValue (ShAmt->getType ()));
1085
+ Cond = IRB->CreateICmpULT (ShAmt, IRB->getInt32 (32 ));
1089
1086
1090
1087
if (Cond == IRB->getTrue () || InnerTBB) {
1091
1088
if (InnerTBB) IRB->SetInsertPoint (&(*InnerTBB->begin ()));
0 commit comments