[llvm] 9100228 - [InstCombine] Fix insertion point

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 06:27:25 PST 2023


Author: Nikita Popov
Date: 2023-12-14T15:27:17+01:00
New Revision: 9100228e455bfe992e291e060c5b697d8403956e

URL: https://github.com/llvm/llvm-project/commit/9100228e455bfe992e291e060c5b697d8403956e
DIFF: https://github.com/llvm/llvm-project/commit/9100228e455bfe992e291e060c5b697d8403956e.diff

LOG: [InstCombine] Fix insertion point

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
    llvm/test/Transforms/InstCombine/and.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 18d4c2dc308e2e..846116a929b156 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -556,8 +556,11 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
     {
       const APInt *C;
       if (match(I->getOperand(1), m_APInt(C)) &&
-          C->isOneBitSet(DemandedMask.getActiveBits() - 1))
+          C->isOneBitSet(DemandedMask.getActiveBits() - 1)) {
+        IRBuilderBase::InsertPointGuard Guard(Builder);
+        Builder.SetInsertPoint(I);
         return Builder.CreateXor(I->getOperand(0), ConstantInt::get(VTy, *C));
+      }
     }
 
     // Otherwise just compute the known bits of the result.

diff  --git a/llvm/test/Transforms/InstCombine/and.ll b/llvm/test/Transforms/InstCombine/and.ll
index cb611764ec755b..2e37fee07cc47b 100644
--- a/llvm/test/Transforms/InstCombine/and.ll
+++ b/llvm/test/Transforms/InstCombine/and.ll
@@ -2755,3 +2755,16 @@ define i32 @add_constant_equal_with_the_top_bit_of_demandedbits_fail2(i32 %x) {
   %and = and i32 %add, 24
   ret i32 %and
 }
+
+define i32 @add_constant_equal_with_the_top_bit_of_demandedbits_insertpt(i32 %x, i32 %y) {
+; CHECK-LABEL: @add_constant_equal_with_the_top_bit_of_demandedbits_insertpt(
+; CHECK-NEXT:    [[TMP1:%.*]] = xor i32 [[X:%.*]], 16
+; CHECK-NEXT:    [[OR:%.*]] = or i32 [[TMP1]], [[Y:%.*]]
+; CHECK-NEXT:    [[AND:%.*]] = and i32 [[OR]], 24
+; CHECK-NEXT:    ret i32 [[AND]]
+;
+  %add = add i32 %x, 16
+  %or = or i32 %add, %y
+  %and = and i32 %or, 24
+  ret i32 %and
+}


        


More information about the llvm-commits mailing list